Skip to content

Commit 350770c

Browse files
committed
test: Fix Namespace Collisions in Unit Tests exposed by setupClass Guardrail (#8876)
1 parent 1177058 commit 350770c

7 files changed

Lines changed: 22 additions & 14 deletions

File tree

src/Neo.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,10 @@ If you intended to create custom logic, use the 'beforeGet${Neo.capitalize(key)}
813813
* Example: code.LivePreview running inside a dist/production app.
814814
*/
815815
if (ns) {
816+
if (Neo.config.unitTestMode) {
817+
throw new Error('Namespace collision in unitTestMode for ' + proto.constructor.config.className)
818+
}
819+
816820
return ns
817821
}
818822

test/playwright/unit/core/ClassConfigsAndFields.spec.mjs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TestClass extends core.Base {
1111
fieldB = 2;
1212

1313
static config = {
14-
className: 'Neo.TestClass',
14+
className: 'Test.Unit.Core.ClassConfigsAndFields.TestClass',
1515
configA_ : 3,
1616
configB_ : 4
1717
}
@@ -65,6 +65,10 @@ test.describe('ClassConfigsAndFields', () => {
6565

6666
test('Neo default class fields inside constructors', () => {
6767
class NeoCtorTest extends core.Base {
68+
static config = {
69+
className: 'Test.Unit.Core.ClassConfigsAndFields.NeoCtorTest'
70+
}
71+
6872
fieldA = 1;
6973
fieldB = 2;
7074

@@ -153,7 +157,7 @@ test.describe('ClassConfigsAndFields', () => {
153157

154158
test('Class based class configs and fields', () => {
155159
const instance = Neo.create({
156-
className: 'Neo.TestClass'
160+
className: 'Test.Unit.Core.ClassConfigsAndFields.TestClass'
157161
});
158162

159163
expect(instance.configA).toBe(4); // 1 + 3
@@ -164,7 +168,7 @@ test.describe('ClassConfigsAndFields', () => {
164168

165169
test('Instance based class configs and fields', () => {
166170
const instance = Neo.create({
167-
className: 'Neo.TestClass',
171+
className: 'Test.Unit.Core.ClassConfigsAndFields.TestClass',
168172
fieldA : 5,
169173
configA : 6,
170174
configB : 7,
@@ -177,7 +181,7 @@ test.describe('ClassConfigsAndFields', () => {
177181
expect(instance.fieldB).toBe(8);
178182

179183
const instance2 = Neo.create({
180-
className: 'Neo.TestClass',
184+
className: 'Test.Unit.Core.ClassConfigsAndFields.TestClass',
181185
fieldB : 8,
182186
configB : 7,
183187
configA : 6,
@@ -192,7 +196,7 @@ test.describe('ClassConfigsAndFields', () => {
192196

193197
test('Dynamically changed class configs and fields', () => {
194198
const instance = Neo.create({
195-
className: 'Neo.TestClass'
199+
className: 'Test.Unit.Core.ClassConfigsAndFields.TestClass'
196200
});
197201

198202
instance.set({
@@ -208,7 +212,7 @@ test.describe('ClassConfigsAndFields', () => {
208212
expect(instance.fieldB).toBe(8);
209213

210214
const instance2 = Neo.create({
211-
className: 'Neo.TestClass'
215+
className: 'Test.Unit.Core.ClassConfigsAndFields.TestClass'
212216
});
213217

214218
instance2.set({

test/playwright/unit/core/ClassSystem.spec.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test.describe('ClassSystem', () => {
2222

2323
class TestClass extends core.Base {
2424
static config = {
25-
className: 'Neo.TestClass',
25+
className: 'Test.Unit.Core.ClassSystem.TestClass',
2626
a_ : valueA,
2727
b_ : valueB
2828
}

test/playwright/unit/state/ProviderNestedDataConfigs.spec.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import StateProvider from '../../../../src/state/Provider.mjs';
1515

1616
class MockComponent extends Component {
1717
static config = {
18-
className: 'Mock.Component',
18+
className: 'Test.Unit.State.ProviderNestedDataConfigs.MockComponent',
1919
appName : 'test-app',
2020
user_ : null,
2121
userName_: null

test/playwright/unit/vdom/TreeBuilder.spec.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import TreeBuilder from '../../../../src/util/vdom/TreeBuilder.mjs';
1919

2020
class MockComponent extends Component {
2121
static config = {
22-
className: 'Test.MockComponent',
23-
ntype: 'test-mock',
22+
className: 'Test.Unit.Vdom.TreeBuilder.MockComponent',
23+
ntype: 'test-unit-vdom-treebuilder-mock',
2424
_vdom: {tag: 'div'}
2525
}
2626
}

test/playwright/unit/vdom/VdomLifecycle.spec.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ Neo.applyDeltas = async () => {};
2525

2626
class MockComponent extends Component {
2727
static config = {
28-
className: 'Test.MockComponent',
29-
ntype: 'test-mock',
28+
className: 'Test.Unit.Vdom.VdomLifecycle.MockComponent',
29+
ntype: 'test-unit-vdom-vdomlifecycle-mock',
3030
hideMode: 'removeDom',
3131
_vdom: {tag: 'div', cls: ['child']}
3232
}

test/playwright/unit/vdom/VdomMerging.spec.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import VdomHelper from '../../../../src/vdom/Helper.mjs';
2626

2727
class TestContainer extends Container {
2828
static config = {
29-
className: 'Test.Container',
30-
ntype : 'test-container',
29+
className: 'Test.Unit.Vdom.VdomMerging.Container',
30+
ntype : 'test-unit-vdom-vdommerging-container',
3131
layout : {ntype: 'vbox'},
3232
style : {color: 'black'}
3333
}

0 commit comments

Comments
 (0)