diff --git a/src/core/assert/assert.unit.ts b/src/core/assert/assert.unit.ts deleted file mode 100644 index b5370ece9cb..00000000000 --- a/src/core/assert/assert.unit.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** - * @license - * Copyright Builder.io, Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE - */ diff --git a/src/core/component/component.unit.ts b/src/core/component/component.unit.ts index cd424e1e4ce..af5526bb4ec 100644 --- a/src/core/component/component.unit.ts +++ b/src/core/component/component.unit.ts @@ -6,11 +6,11 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { ComponentFixture, GreeterComponent } from '../testing/component_fixture.js'; -import { AttributeMarker } from '../util/markers.js'; -import { Component } from './component.js'; -import { injectMethod } from '../injector/inject.js'; +import { ComponentFixture } from '@builder.io/qwik/testing'; +import { GreeterComponent } from '../util/test_component_fixture'; +import { AttributeMarker } from '../util/markers'; +import { Component } from './component'; +import { injectMethod } from '../injector/inject'; describe('component', () => { it('should declare a component', async () => { @@ -22,8 +22,8 @@ describe('component', () => { fixture.host.setAttribute('salutation', 'Hello'); fixture.host.setAttribute('name', 'World'); const greeter = await fixture.injector.getComponent(GreeterComponent); - expect(greeter.$props).to.eql({ salutation: 'Hello', name: 'World' }); - expect(greeter.$state).to.eql({ greeting: 'Hello World!' }); + expect(greeter.$props).toEqual({ salutation: 'Hello', name: 'World' }); + expect(greeter.$state).toEqual({ greeting: 'Hello World!' }); }); it('should call $init state', () => { @@ -34,7 +34,7 @@ describe('component', () => { } } const myComponent = new MyComponent(fixture.host, 'props', 'state'); - expect(myComponent).to.eql({ + expect(myComponent).toEqual({ $state: 'state', $props: 'props', $host: fixture.host, diff --git a/src/core/entity/entity.unit.ts b/src/core/entity/entity.unit.ts index fdddff75eb5..174deb9eace 100644 --- a/src/core/entity/entity.unit.ts +++ b/src/core/entity/entity.unit.ts @@ -6,17 +6,15 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { assertDefined } from '../assert/assert.js'; -import { TEST_CONFIG } from '../testing/config.unit.js'; -import { stringifyDebug } from '../error/stringify.js'; -import { QRL } from '../import/qrl.js'; -import { getInjector } from '../injector/element_injector.js'; -import { injectMethod } from '../injector/inject.js'; -import { serializeState } from '../render/serialize_state.js'; -import { ElementFixture } from '../testing/element_fixture.js'; -import { Entity, EntityConstructor } from './entity.js'; -import type { EntityKey } from './entity_key.js'; +import { assertDefined } from '../assert/assert'; +import { TEST_CONFIG } from '../util/test_config'; +import { stringifyDebug } from '../error/stringify'; +import { QRL } from '../import/qrl'; +import { getInjector } from '../injector/element_injector'; +import { injectMethod } from '../injector/inject'; +import { ElementFixture, serializeState } from '@builder.io/qwik/testing'; +import { Entity, EntityConstructor } from './entity'; +import type { EntityKey } from './entity_key'; export const __verify_Entity_subtype_of_EntityType__: EntityConstructor = Entity; const entity: Entity = null!; @@ -37,7 +35,7 @@ describe('entity', () => { it('should attach', () => { const fixture = new ElementFixture(TEST_CONFIG); GreeterEntity.$attachEntity(fixture.host); - expect(stringifyDebug(fixture.host)).to.eql( + expect(stringifyDebug(fixture.host)).toEqual( `` ); }); @@ -46,26 +44,26 @@ describe('entity', () => { const fixture = new ElementFixture(TEST_CONFIG); GreeterEntity.$attachEntity(fixture.host); GreeterEntity.$attachEntity(fixture.host); - expect(stringifyDebug(fixture.host)).to.eql( + expect(stringifyDebug(fixture.host)).toEqual( `` ); }); it('should error', () => { - expect(() => Entity.$attachEntity.apply(MissingNameEntity as any, null!)).to.throw( + expect(() => Entity.$attachEntity.apply(MissingNameEntity as any, null!)).toThrow( `SERVICE-ERROR(Q-310): Entity 'MissingNameEntity' must have static '$type' property defining the name of the entity.` ); - expect(() => Entity.$attachEntity.apply(EmptyNameEntity as any, null!)).to.throw( + expect(() => Entity.$attachEntity.apply(EmptyNameEntity as any, null!)).toThrow( `SERVICE-ERROR(Q-310): Entity 'EmptyNameEntity' must have static '$type' property defining the name of the entity.` ); - expect(() => Entity.$attachEntity.apply(MissingKeyPropsEntity as any, null!)).to.throw( + expect(() => Entity.$attachEntity.apply(MissingKeyPropsEntity as any, null!)).toThrow( `SERVICE-ERROR(Q-312): Entity 'MissingKeyPropsEntity' must have static '$qrl' property defining the import location of the entity.` ); }); it('should error on QRL collision', () => { const fixture = new ElementFixture(TEST_CONFIG); fixture.host.setAttribute('::greeter', 'some_other_qrl'); - expect(() => GreeterEntity.$attachEntity(fixture.host)).to.throw( + expect(() => GreeterEntity.$attachEntity(fixture.host)).toThrow( `SERVICE-ERROR(Q-313): Name collision. Already have entity named 'Greeter' with QRL 'some_other_qrl' but expected QRL 'entity:/entity.unit#GreeterEntity'.` ); }); @@ -84,7 +82,7 @@ describe('entity', () => { { salutation: 'ahoj', name: 'svet' }, { greeting: 'Ahoj Svet!' } ); - expect(stringifyDebug(fixture.host)).to.eql( + expect(stringifyDebug(fixture.host)).toEqual( `` @@ -100,10 +98,10 @@ describe('entity', () => { { salutation: 'Hello', name: 'World' }, { greeting: 'existing state' } ); - expect(greeterPromise.$key).to.eql('greeter:-hello:-world'); + expect(greeterPromise.$key).toEqual('greeter:-hello:-world'); const greeter = await greeterPromise; - expect(greeter.$state).to.eql({ $key: 'greeter:-hello:-world', greeting: 'existing state' }); - expect(stringifyDebug(fixture.host)).to.eql( + expect(greeter.$state).toEqual({ $key: 'greeter:-hello:-world', greeting: 'existing state' }); + expect(stringifyDebug(fixture.host)).toEqual( `` ); }); @@ -113,13 +111,13 @@ describe('entity', () => { salutation: 'Hello', name: 'World', }); - expect(greeterPromise.$key).to.eql('greeter:-hello:-world'); + expect(greeterPromise.$key).toEqual('greeter:-hello:-world'); const greeter = await greeterPromise; - expect(greeter.$state).to.eql({ + expect(greeter.$state).toEqual({ $key: 'greeter:-hello:-world', greeting: 'INIT: Hello World!', }); - expect(stringifyDebug(fixture.host)).to.eql( + expect(stringifyDebug(fixture.host)).toEqual( `` ); }); @@ -129,21 +127,21 @@ describe('entity', () => { salutation: 'Hello', name: 'World', }); - expect(greeterPromise).to.equal(GreeterEntity.$hydrate(fixture.host, greeterHelloWorldKey)); - expect(await greeterPromise).to.equal( + expect(greeterPromise).toEqual(GreeterEntity.$hydrate(fixture.host, greeterHelloWorldKey)); + expect(await greeterPromise).toEqual( await GreeterEntity.$hydrate(fixture.host, greeterHelloWorldKey) ); }); it('should hydrate without state using key', async () => { const fixture = new ElementFixture(TEST_CONFIG); const greeterPromise = GreeterEntity.$hydrate(fixture.host, greeterHelloWorldKey); - expect(greeterPromise.$key).to.eql('greeter:-hello:-world'); + expect(greeterPromise.$key).toEqual('greeter:-hello:-world'); const greeter = await greeterPromise; - expect(greeter.$state).to.eql({ + expect(greeter.$state).toEqual({ $key: 'greeter:-hello:-world', greeting: 'INIT: Hello World!', }); - expect(stringifyDebug(fixture.host)).to.eql( + expect(stringifyDebug(fixture.host)).toEqual( `` ); }); @@ -153,12 +151,12 @@ describe('entity', () => { salutation: 'throw', name: 'World', }); - expect(greeterPromise.$key).to.eql('greeter:throw:-world'); + expect(greeterPromise.$key).toEqual('greeter:throw:-world'); try { await greeterPromise; - expect('not to get here').to.be.false; + expect('not to get here').toBeFalsy(); } catch (e) { - expect(String(e)).to.contain('Error: World'); + expect(String(e)).toContain('Error: World'); } }); it('should deserialize entity from DOM', async () => { @@ -172,13 +170,13 @@ describe('entity', () => { const injector = getInjector(fixture.child); const greeterPromise = injector.getEntityState(greeterAhojSvetKey); const greeter: Greeter = await greeterPromise; - expect(greeter).to.eql({ $key: 'greeter:ahoj:svet', greeting: 'Ahoj Svet!' }); + expect(greeter).toEqual({ $key: 'greeter:ahoj:svet', greeting: 'Ahoj Svet!' }); const entityPromise = getInjector(fixture.child).getEntity(greeterAhojSvetKey); const greeterEntity = await entityPromise; - expect(greeterEntity).to.be.instanceOf(GreeterEntity); - expect(greeterEntity.$props).to.eql({ salutation: 'ahoj', name: 'svet' }); - expect(greeterEntity.$state).to.eql({ $key: 'greeter:ahoj:svet', greeting: 'Ahoj Svet!' }); + expect(greeterEntity).toBeInstanceOf(GreeterEntity); + expect(greeterEntity.$props).toEqual({ salutation: 'ahoj', name: 'svet' }); + expect(greeterEntity.$state).toEqual({ $key: 'greeter:ahoj:svet', greeting: 'Ahoj Svet!' }); }); }); @@ -186,11 +184,11 @@ describe('entity', () => { it('should create an instance and invoke identity method', async () => { const fixture = new ElementFixture(TEST_CONFIG); const empty = await EmptyEntity.$hydrate(fixture.child, {}, {}); - expect(await empty.ident('ABC')).to.equal('ABC'); - expect(await getInjector(fixture.child).getEntity('empty:' as any as EntityKey)).to.equal( + expect(await empty.ident('ABC')).toEqual('ABC'); + expect(await getInjector(fixture.child).getEntity('empty:' as any as EntityKey)).toEqual( empty ); - expect(fixture.child.getAttribute('::empty')).to.equal('entity:/entity.unit#EmptyEntity'); + expect(fixture.child.getAttribute('::empty')).toEqual('entity:/entity.unit#EmptyEntity'); }); }); @@ -201,25 +199,25 @@ describe('entity', () => { name: 'world', }); const greeter = await greeterPromise; - expect(greeter.$state.greeting).to.equal('INIT: hello world!'); - expect(await greeter.greet()).to.equal('hello world!'); - expect(greeter.$state.greeting).to.equal('hello world!'); - expect(stringifyDebug(greeter.$element)).to.equal( + expect(greeter.$state.greeting).toEqual('INIT: hello world!'); + expect(await greeter.greet()).toEqual('hello world!'); + expect(greeter.$state.greeting).toEqual('hello world!'); + expect(stringifyDebug(greeter.$element)).toEqual( "" ); expect( await getInjector(fixture.child).getEntity( 'greeter:hello:world' as any as EntityKey ) - ).to.equal(greeter); + ).toEqual(greeter); serializeState(fixture.host); - expect(stringifyDebug(greeter.$element)).to.equal( + expect(stringifyDebug(greeter.$element)).toEqual( `` ); greeter.$release(); - expect(stringifyDebug(greeter.$element)).to.equal( + expect(stringifyDebug(greeter.$element)).toEqual( `` ); }); diff --git a/src/core/entity/entity_key.unit.ts b/src/core/entity/entity_key.unit.ts index c4d810e6c3f..e5d0a5a4d3a 100644 --- a/src/core/entity/entity_key.unit.ts +++ b/src/core/entity/entity_key.unit.ts @@ -6,15 +6,14 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import type { EntityConstructor } from './entity.js'; +import type { EntityConstructor } from './entity'; import { entityStateKey, keyToEntityAttribute, keyToProps, propsToKey, validateKeyPart, -} from './entity_key.js'; +} from './entity_key'; describe('entity key', () => { const MissingKeyPropsEntity: EntityConstructor = class MissingKeyPropsEntity { @@ -30,18 +29,18 @@ describe('entity key', () => { } as any; describe('propsToKey', () => { it('should convert prop to key', () => { - expect(propsToKey(MockEntity, {})).to.eql('my-entity:::'); - expect(propsToKey(MockEntity, { a: 12 })).to.eql('my-entity:12::'); - expect(propsToKey(MockEntity, { a: 12, propB: 3, c: 4 })).to.eql('my-entity:12:3:4'); - expect(propsToKey(MockEntity, { a: null, propB: undefined, c: 4 })).to.eql('my-entity:::4'); - expect(propsToKey(MockEntity, { a: 'A', propB: 'aA' })).to.eql('my-entity:-a:a-a:'); + expect(propsToKey(MockEntity, {})).toEqual('my-entity:::'); + expect(propsToKey(MockEntity, { a: 12 })).toEqual('my-entity:12::'); + expect(propsToKey(MockEntity, { a: 12, propB: 3, c: 4 })).toEqual('my-entity:12:3:4'); + expect(propsToKey(MockEntity, { a: null, propB: undefined, c: 4 })).toEqual('my-entity:::4'); + expect(propsToKey(MockEntity, { a: 'A', propB: 'aA' })).toEqual('my-entity:-a:a-a:'); }); it('should error', () => { - expect(() => propsToKey(MissingKeyPropsEntity, {})).to.throw( + expect(() => propsToKey(MissingKeyPropsEntity, {})).toThrow( `SERVICE-ERROR(Q-311): Entity 'MissingKeyPropsEntity' does not define '$keyProps'.` ); - expect(() => propsToKey(MockEntity, { a: '.' })).to.throw( + expect(() => propsToKey(MockEntity, { a: '.' })).toThrow( `SERVICE-ERROR(Q-303): '.' is not a valid attribute. Attributes can only contain 'a-z' (lowercase), '0-9', '-' and '_'.` ); }); @@ -49,33 +48,33 @@ describe('entity key', () => { describe('keyToProps', () => { it('should convert key', () => { - expect(keyToProps(MockEntity, `my-entity:1:234:56`)).to.eql({ + expect(keyToProps(MockEntity, `my-entity:1:234:56`)).toEqual({ a: '1', propB: '234', c: '56', }); - expect(keyToProps(MockEntity, `my-entity:1:234`)).to.eql({ a: '1', propB: '234', c: null }); - expect(keyToProps(MockEntity, `my-entity:-a:a-a:-a-a`)).to.eql({ + expect(keyToProps(MockEntity, `my-entity:1:234`)).toEqual({ a: '1', propB: '234', c: null }); + expect(keyToProps(MockEntity, `my-entity:-a:a-a:-a-a`)).toEqual({ a: 'A', propB: 'aA', c: 'AA', }); - expect(keyToProps(MockEntity, `my-entity:1`)).to.eql({ a: '1', propB: null, c: null }); - expect(keyToProps(MockEntity, `my-entity:`)).to.eql({ a: null, propB: null, c: null }); - expect(keyToProps(MockEntity, `my-entity::`)).to.eql({ a: '', propB: null, c: null }); - expect(keyToProps(EmptyEntity, `empty-entity:`)).to.eql({}); + expect(keyToProps(MockEntity, `my-entity:1`)).toEqual({ a: '1', propB: null, c: null }); + expect(keyToProps(MockEntity, `my-entity:`)).toEqual({ a: null, propB: null, c: null }); + expect(keyToProps(MockEntity, `my-entity::`)).toEqual({ a: '', propB: null, c: null }); + expect(keyToProps(EmptyEntity, `empty-entity:`)).toEqual({}); }); it('should error', () => { - expect(() => keyToProps(MissingKeyPropsEntity, `my-entity::`)).to.throw( + expect(() => keyToProps(MissingKeyPropsEntity, `my-entity::`)).toThrow( `SERVICE-ERROR(Q-311): Entity 'MissingKeyPropsEntity' does not define '$keyProps'.` ); - expect(() => keyToProps(MockEntity, `my-entity`)).to.throw( + expect(() => keyToProps(MockEntity, `my-entity`)).toThrow( `SERVICE-ERROR(Q-309): Entity key 'my-entity' is missing values. Expecting 'my-entity:someValue'.` ); - expect(() => keyToProps(MockEntity, `other-entity:`)).to.throw( + expect(() => keyToProps(MockEntity, `other-entity:`)).toThrow( `SERVICE-ERROR(Q-315): Key 'other-entity:' belongs to entity named 'other-entity', but expected entity 'MockEntity' with name 'my-entity'.` ); - expect(() => keyToProps(MockEntity, `my-entity::::`)).to.throw( + expect(() => keyToProps(MockEntity, `my-entity::::`)).toThrow( `SERVICE-ERROR(Q-314): Entity 'MockEntity' defines '$keyProps' as '["a","propB","c"]'. Actual key 'my-entity::::' has more parts than entity defines.` ); }); @@ -83,13 +82,13 @@ describe('entity key', () => { describe('keyToEntityName', () => { it('should extract entity name', () => { - expect(keyToEntityAttribute('foo:')).to.eql('::foo'); - expect(keyToEntityAttribute('bar:baz')).to.eql('::bar'); - expect(keyToEntityAttribute('bar:baz:qwik')).to.eql('::bar'); - expect(keyToEntityAttribute(':')).to.eql('::'); + expect(keyToEntityAttribute('foo:')).toEqual('::foo'); + expect(keyToEntityAttribute('bar:baz')).toEqual('::bar'); + expect(keyToEntityAttribute('bar:baz:qwik')).toEqual('::bar'); + expect(keyToEntityAttribute(':')).toEqual('::'); }); it('should complain on bad format', () => { - expect(() => keyToEntityAttribute('foo')).to.throw( + expect(() => keyToEntityAttribute('foo')).toThrow( `SERVICE-ERROR(Q-300): Data key 'foo' is not a valid key.\n` + ` - Data key can only contain characters (preferably lowercase) or number\n` + ` - Data key is prefixed with entity name\n` + @@ -100,19 +99,19 @@ describe('entity key', () => { describe('validateKeyPart', () => { it('should allow valid keys', () => { - expect(validateKeyPart('')).to.eql(''); - expect(validateKeyPart('lowercase')).to.eql('lowercase'); - expect(validateKeyPart('with_under-dash')).to.eql('with_under-dash'); + expect(validateKeyPart('')).toEqual(''); + expect(validateKeyPart('lowercase')).toEqual('lowercase'); + expect(validateKeyPart('with_under-dash')).toEqual('with_under-dash'); }); it('should throw on invalid characters', () => { - expect(() => validateKeyPart(':')).to.throw( + expect(() => validateKeyPart(':')).toThrow( `SERVICE-ERROR(Q-303): ':' is not a valid attribute. Attributes can only contain 'a-z' (lowercase), '0-9', '-' and '_'.` ); - expect(() => validateKeyPart('with.dot')).to.throw( + expect(() => validateKeyPart('with.dot')).toThrow( `SERVICE-ERROR(Q-303): 'with.dot' is not a valid attribute. Attributes can only contain 'a-z' (lowercase), '0-9', '-' and '_'.` ); - expect(() => validateKeyPart('mixCase')).to.throw( + expect(() => validateKeyPart('mixCase')).toThrow( `SERVICE-ERROR(Q-303): 'mixCase' is not a valid attribute. Attributes can only contain 'a-z' (lowercase), '0-9', '-' and '_'.` ); }); @@ -120,11 +119,11 @@ describe('entity key', () => { describe('entityStateKey', () => { it('should retrieve key', () => { - expect(entityStateKey({ $key: 'theKey' })).to.equal('theKey'); + expect(entityStateKey({ $key: 'theKey' })).toEqual('theKey'); }); describe('error', () => { it('should throw error if not a key is passed in', () => { - expect(() => entityStateKey({ something: 1 })).to.throw( + expect(() => entityStateKey({ something: 1 })).toThrow( `SERVICE-ERROR(Q-316): Entity state is missing '$key'. Are you sure you passed in state? Got '{"something":1}'.` ); }); diff --git a/src/core/error/error.unit.ts b/src/core/error/error.unit.ts deleted file mode 100644 index b5370ece9cb..00000000000 --- a/src/core/error/error.unit.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** - * @license - * Copyright Builder.io, Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE - */ diff --git a/src/core/event/emit_event.unit.ts b/src/core/event/emit_event.unit.ts index 4753370d7cf..6108f45bfa0 100644 --- a/src/core/event/emit_event.unit.ts +++ b/src/core/event/emit_event.unit.ts @@ -6,14 +6,13 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { TEST_CONFIG } from '../testing/config.unit.js'; -import { ElementFixture } from '../testing/element_fixture.js'; -import { emitEvent } from './emit_event.js'; -import { injectEventHandler } from './inject_event_handler.js'; -import { provideElement } from './provide_element.js'; -import { provideEvent } from './provide_event.js'; -import { provideURL } from './provide_url.js'; +import { TEST_CONFIG } from '../util/test_config'; +import { ElementFixture } from '@builder.io/qwik/testing'; +import { emitEvent } from './emit_event'; +import { injectEventHandler } from './inject_event_handler'; +import { provideElement } from './provide_element'; +import { provideEvent } from './provide_event'; +import { provideURL } from './provide_url'; import type { EventHandler } from './types'; describe('emitEvent', () => { @@ -28,31 +27,31 @@ describe('emitEvent', () => { const eventHandler: EventHandler = emitEvent as typeof emitEvent & { $delegate: any; }; - expect(eventHandler).to.equal(emitEvent); + expect(eventHandler).toEqual(emitEvent); }); it('should re-emit an event', async () => { const url = new URL('http://localhost/path#emitEvent?$type=openMe&someKey=someValue'); fixture.parent.setAttribute('on:open-me', 'test:event/emit_event.unit#echo?key=value'); const retValue = await emitEvent(fixture.host, event, url); - expect(retValue.element).to.eql(fixture.parent); - expect(String(retValue.url)).to.contains('event/emit_event.unit#echo?key=value'); - expect(retValue.event.type).to.eql('openMe'); - expect(retValue.event.someKey).to.eql('someValue'); + expect(retValue.element).toEqual(fixture.parent); + expect(String(retValue.url)).toContain('event/emit_event.unit#echo?key=value'); + expect(retValue.event.type).toEqual('openMe'); + expect(retValue.event.someKey).toEqual('someValue'); }); describe('error handling', () => { it('should throw if missing $type', () => { const url = new URL('http://localhost/path'); const event: Event = 'event' as any; - expect(() => emitEvent(fixture.host, event, url)).to.throw( + expect(() => emitEvent(fixture.host, event, url)).toThrow( "EVENT-ERROR(Q-700): Missing '$type' attribute in the 'http://localhost/path' url." ); }); it('should throw if no listener', () => { const url = new URL('http://localhost/path#?$type=dontexist'); const event: Event = 'event' as any; - expect(() => emitEvent(fixture.host, event, url)).to.throw( + expect(() => emitEvent(fixture.host, event, url)).toThrow( "EVENT-ERROR(Q-701): Re-emitting event 'on:dontexist' but no listener found at '' or any of its parents." ); }); diff --git a/src/core/event/event_injector.unit.ts b/src/core/event/event_injector.unit.ts index 53c9c50b309..2d6f2d5add5 100644 --- a/src/core/event/event_injector.unit.ts +++ b/src/core/event/event_injector.unit.ts @@ -6,10 +6,9 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { ElementFixture } from '../testing/element_fixture.js'; -import { EventInjector } from './event_injector.js'; -import { EventEntity } from './event_entity.js'; +import { ElementFixture } from '@builder.io/qwik/testing'; +import { EventInjector } from './event_injector'; +import { EventEntity } from './event_entity'; describe('EventInjector', () => { let fixture: ElementFixture; @@ -20,8 +19,8 @@ describe('EventInjector', () => { const url = new URL('http://localhost/path#?a=b&c=d'); const eventInjector = new EventInjector(fixture.host, event, url); const eventEntity = await eventInjector.getEntity(EventEntity.KEY); - expect(eventEntity.event).to.equal(event); - expect(eventEntity.url).to.equal(url); - expect(eventEntity.props).to.eql({ a: 'b', c: 'd' }); + expect(eventEntity.event).toEqual(event); + expect(eventEntity.url).toEqual(url); + expect(eventEntity.props).toEqual({ a: 'b', c: 'd' }); }); }); diff --git a/src/core/event/inject_event_handler.unit.ts b/src/core/event/inject_event_handler.unit.ts index c3d691b26bc..8c9a8ee9ef6 100644 --- a/src/core/event/inject_event_handler.unit.ts +++ b/src/core/event/inject_event_handler.unit.ts @@ -6,14 +6,13 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { Component } from '../component/index.js'; -import type { QRL } from '../import/qrl.js'; -import { ElementFixture } from '../testing/element_fixture.js'; -import { AttributeMarker } from '../util/markers.js'; -import { EventEntity } from './event_entity.js'; -import type { EventInjector } from './event_injector.js'; -import { injectEventHandler } from './inject_event_handler.js'; +import { Component } from '../component/index'; +import type { QRL } from '../import/qrl'; +import { ElementFixture } from '@builder.io/qwik/testing'; +import { AttributeMarker } from '../util/markers'; +import { EventEntity } from './event_entity'; +import type { EventInjector } from './event_injector'; +import { injectEventHandler } from './inject_event_handler'; describe('injectEventHandler', () => { let fixture: ElementFixture; @@ -28,18 +27,18 @@ describe('injectEventHandler', () => { MyComponent, async (injector: EventInjector) => { const eventEntity = await injector.getEntity(EventEntity.KEY); - expect(injector.element).to.equal(fixture.host); - expect(eventEntity.event).to.equal(event); - expect(eventEntity.url).to.equal(url); + expect(injector.element).toEqual(fixture.host); + expect(eventEntity.event).toEqual(event); + expect(eventEntity.url).toEqual(url); return 'providerValue'; }, function (this: MyComponent, arg0: string) { - expect(this.$host).to.equal(fixture.host); - expect(arg0).to.equal('providerValue'); + expect(this.$host).toEqual(fixture.host); + expect(arg0).toEqual('providerValue'); return 'handlerValue'; } ); - expect(await fn(fixture.host, event, url)).to.equal('handlerValue'); + expect(await fn(fixture.host, event, url)).toEqual('handlerValue'); }); }); diff --git a/src/core/event/provide_element.unit.ts b/src/core/event/provide_element.unit.ts index fc07eb7778f..78c10433b74 100644 --- a/src/core/event/provide_element.unit.ts +++ b/src/core/event/provide_element.unit.ts @@ -6,10 +6,9 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { ElementFixture } from '../testing/element_fixture.js'; -import { EventInjector } from './event_injector.js'; -import { provideElement } from './provide_element.js'; +import { ElementFixture } from '@builder.io/qwik/testing'; +import { EventInjector } from './event_injector'; +import { provideElement } from './provide_element'; describe('provideElement', () => { let fixture: ElementFixture; @@ -24,6 +23,6 @@ describe('provideElement', () => { }); it('should return element', async () => { - expect(await provideElement()(eventInjector)).to.equal(eventInjector.element); + expect(await provideElement()(eventInjector)).toEqual(eventInjector.element); }); }); diff --git a/src/core/event/provide_event.unit.ts b/src/core/event/provide_event.unit.ts index 8d33477b0c0..a540c4f454a 100644 --- a/src/core/event/provide_event.unit.ts +++ b/src/core/event/provide_event.unit.ts @@ -6,10 +6,9 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { ElementFixture } from '../testing/element_fixture.js'; -import { EventInjector } from './event_injector.js'; -import { provideEvent } from './provide_event.js'; +import { ElementFixture } from '@builder.io/qwik/testing'; +import { EventInjector } from './event_injector'; +import { provideEvent } from './provide_event'; describe('provideEvent', () => { let fixture: ElementFixture; @@ -24,6 +23,6 @@ describe('provideEvent', () => { }); it('should return url', async () => { - expect(await provideEvent()(eventInjector)).to.equal(event); + expect(await provideEvent()(eventInjector)).toEqual(event); }); }); diff --git a/src/core/event/provide_qrl_exp.unit.ts b/src/core/event/provide_qrl_exp.unit.ts index bfc820ca9c3..e47907672fe 100644 --- a/src/core/event/provide_qrl_exp.unit.ts +++ b/src/core/event/provide_qrl_exp.unit.ts @@ -6,11 +6,10 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { ComponentFixture } from '../testing/component_fixture.js'; -import { EventInjector } from '../event/event_injector.js'; -import { injectFunction } from '../injector/inject.js'; -import { provideQrlExp } from './provide_qrl_exp.js'; +import { ComponentFixture } from '@builder.io/qwik/testing'; +import { EventInjector } from '../event/event_injector'; +import { injectFunction } from '../injector/inject'; +import { provideQrlExp } from './provide_qrl_exp'; describe('provideQrlExp', () => { it('should inject properties from event object', async () => { @@ -18,13 +17,13 @@ describe('provideQrlExp', () => { const injector = new EventInjector( fixture.child, { foo: { bar: 'worked' } } as any, - new URL('./provide_qrl_exp.unit.someExport#?value=.foo.bar', import.meta.url) + new URL('./provide_qrl_exp.unit.someExport#?value=.foo.bar', 'http://testing.qwik.dev') ); const handler = injectFunction(provideQrlExp('value'), (props) => { return props; }); - expect(await provideQrlExp('value')(injector)).to.eql('worked'); - expect(await injector.invoke(handler)).to.eql('worked'); + expect(await provideQrlExp('value')(injector)).toEqual('worked'); + expect(await injector.invoke(handler)).toEqual('worked'); }); }); diff --git a/src/core/event/provide_url.unit.ts b/src/core/event/provide_url.unit.ts index 7ac9d405cd6..0b526a71bdf 100644 --- a/src/core/event/provide_url.unit.ts +++ b/src/core/event/provide_url.unit.ts @@ -6,10 +6,9 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { ElementFixture } from '../testing/element_fixture.js'; -import { EventInjector } from './event_injector.js'; -import { provideURL, provideUrlProp } from './provide_url.js'; +import { ElementFixture } from '@builder.io/qwik/testing'; +import { EventInjector } from './event_injector'; +import { provideURL, provideUrlProp } from './provide_url'; describe('provideURL', () => { let fixture: ElementFixture; @@ -24,11 +23,11 @@ describe('provideURL', () => { }); it('should return url', async () => { - expect(await provideURL()(eventInjector)).to.equal(url); + expect(await provideURL()(eventInjector)).toEqual(url); }); it('should return url property', async () => { - expect(await provideUrlProp('a')(eventInjector)).to.equal('b'); - expect(await provideUrlProp('c')(eventInjector)).to.equal('d'); + expect(await provideUrlProp('a')(eventInjector)).toEqual('b'); + expect(await provideUrlProp('c')(eventInjector)).toEqual('d'); }); }); diff --git a/src/core/import/qImport.unit.ts b/src/core/import/qImport.unit.ts index f711d2551ec..8c471733591 100644 --- a/src/core/import/qImport.unit.ts +++ b/src/core/import/qImport.unit.ts @@ -6,29 +6,27 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { TEST_CONFIG } from '../testing/config.unit.js'; -import { qExport, qImport, qParams } from '../import/qImport.js'; -import { isPromise } from '../util/promises.js'; -import { ComponentFixture } from '../testing/component_fixture.js'; +import { TEST_CONFIG } from '../util/test_config'; +import { qExport, qImport, qParams } from '../import/qImport'; +import { ComponentFixture, isPromise } from '@builder.io/qwik/testing'; describe('qImport', () => { it('should import default symbol', async () => { const fixture = new ComponentFixture(TEST_CONFIG); const valuePromise = qImport(fixture.host, 'import:qImport_default_unit'); - expect(isPromise(valuePromise)).to.be.true; - expect(await valuePromise).to.equal('DEFAULT_VALUE'); + expect(isPromise(valuePromise)).toBe(true); + expect(await valuePromise).toEqual('DEFAULT_VALUE'); // second read is direct. - expect(qImport(fixture.host, 'import:qImport_default_unit')).to.equal('DEFAULT_VALUE'); + expect(qImport(fixture.host, 'import:qImport_default_unit')).toEqual('DEFAULT_VALUE'); }); it('should import symbol from extension', async () => { const fixture = new ComponentFixture(TEST_CONFIG); const valuePromise = qImport(fixture.host, '../import/qImport_symbol_unit#mySymbol'); - expect(isPromise(valuePromise)).to.be.true; - expect(await valuePromise).to.equal('MY_SYMBOL_VALUE'); + expect(isPromise(valuePromise)).toBe(true); + expect(await valuePromise).toEqual('MY_SYMBOL_VALUE'); // second read is direct. - expect(qImport(fixture.host, '../import/qImport_symbol_unit#mySymbol')).to.equal( + expect(qImport(fixture.host, '../import/qImport_symbol_unit#mySymbol')).toEqual( 'MY_SYMBOL_VALUE' ); }); @@ -36,43 +34,43 @@ describe('qImport', () => { describe('qExport', () => { it('should return "default" if there is no hash', () => { - expect(qExport(new URL('http://localhost/path'))).to.equal('default'); + expect(qExport(new URL('http://localhost/path'))).toEqual('default'); }); it('should return "default" if there is an empty hash', () => { - expect(qExport(new URL('http://localhost/path#'))).to.equal('default'); + expect(qExport(new URL('http://localhost/path#'))).toEqual('default'); }); it('should extract the export name from the hash', () => { - expect(qExport(new URL('http://localhost/path#abc'))).to.equal('abc'); + expect(qExport(new URL('http://localhost/path#abc'))).toEqual('abc'); }); it('should exclude QRL params from the export name', () => { - expect(qExport(new URL('http://localhost/path#abc?foo=bar'))).to.equal('abc'); - expect(qExport(new URL('http://localhost/path?foo=bar'))).to.equal('default'); - expect(qExport(new URL('http://localhost/path#?foo=bar'))).to.equal('default'); + expect(qExport(new URL('http://localhost/path#abc?foo=bar'))).toEqual('abc'); + expect(qExport(new URL('http://localhost/path?foo=bar'))).toEqual('default'); + expect(qExport(new URL('http://localhost/path#?foo=bar'))).toEqual('default'); }); }); describe('qParams', () => { it('should return an empty params object if there is no export block', () => { - expect(qParams(new URL('http://localhost/path')).toString()).to.equal(''); + expect(qParams(new URL('http://localhost/path')).toString()).toEqual(''); }); it('should return an empty params object if there is no `?` section', () => { - expect(qParams(new URL('http://localhost/path#')).toString()).to.equal(''); - expect(qParams(new URL('http://localhost/path#foo')).toString()).to.equal(''); + expect(qParams(new URL('http://localhost/path#')).toString()).toEqual(''); + expect(qParams(new URL('http://localhost/path#foo')).toString()).toEqual(''); }); it('should extract the params from the `?` section of the export block', () => { let params = qParams(new URL('http://localhost/path#?a=10')); - expect(params.toString()).to.equal('a=10'); - expect(params.get('a')).to.equal('10'); - expect(params.get('b')).to.be.null; + expect(params.toString()).toEqual('a=10'); + expect(params.get('a')).toEqual('10'); + expect(params.get('b')).toBeNull(); params = qParams(new URL('http://localhost/path#?a=10&b=20')); - expect(params.toString()).to.equal('a=10&b=20'); - expect(params.get('a')).to.equal('10'); - expect(params.get('b')).to.equal('20'); + expect(params.toString()).toEqual('a=10&b=20'); + expect(params.get('a')).toEqual('10'); + expect(params.get('b')).toEqual('20'); }); }); diff --git a/src/core/import/qrl.unit.ts b/src/core/import/qrl.unit.ts index 3d7021c11df..47c8cc00d7e 100644 --- a/src/core/import/qrl.unit.ts +++ b/src/core/import/qrl.unit.ts @@ -6,11 +6,10 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { dirname } from '../util/dirname.js'; +import { dirname } from '../util/dirname'; describe('QRL', () => { it('should strip filename and keep ending slash', () => { - expect(dirname('dir/path/file.ext')).to.equal('dir/path/'); + expect(dirname('dir/path/file.ext')).toEqual('dir/path/'); }); }); diff --git a/src/core/injector/base_injector.unit.ts b/src/core/injector/base_injector.unit.ts index 1e5e930e82e..46c3606fe07 100644 --- a/src/core/injector/base_injector.unit.ts +++ b/src/core/injector/base_injector.unit.ts @@ -6,15 +6,13 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { Component } from '../component/component.js'; -import type { QRL } from '../import/qrl.js'; -import { ElementFixture } from '../testing/element_fixture.js'; -import { AttributeMarker } from '../util/markers.js'; -import '../util/qDev.js'; -import { getInjector } from './element_injector.js'; -import { injectFunction, injectMethod } from './inject.js'; -import type { Injector, Provider } from './types.js'; +import { Component } from '../component/component'; +import type { QRL } from '../import/qrl'; +import { ElementFixture } from '@builder.io/qwik/testing'; +import { AttributeMarker } from '../util/markers'; +import { getInjector } from './element_injector'; +import { injectFunction, injectMethod } from './inject'; +import type { Injector, Provider } from './types'; describe('BaseInjector', () => { let fixture: ElementFixture; @@ -25,14 +23,14 @@ describe('BaseInjector', () => { }); describe('getParent', () => { it('should return no parent', () => { - expect(hostInjector.getParent()).to.equal(null); + expect(hostInjector.getParent()).toEqual(null); }); it('should return no parent', () => { - expect(hostInjector.getParent()).to.equal(null); + expect(hostInjector.getParent()).toEqual(null); }); it('should return parent skipping elements with no injectors', () => { fixture.superParent.setAttribute(AttributeMarker.Injector, ''); - expect(hostInjector.getParent()!.element).to.equal(fixture.superParent); + expect(hostInjector.getParent()!.element).toEqual(fixture.superParent); }); }); @@ -48,8 +46,8 @@ describe('BaseInjector', () => { null, 'arg' ) - ).to.eql('ret'); - expect(log).to.eql([null, 'arg']); + ).toEqual('ret'); + expect(log).toEqual([null, 'arg']); }); it('should call injected function', async () => { @@ -62,8 +60,8 @@ describe('BaseInjector', () => { return 'ret'; } ); - expect(await hostInjector.invoke(injectedFn, null, 'extra')).to.eql('ret'); - expect(log).to.eql([null, 'self', 'arg0', 'extra']); + expect(await hostInjector.invoke(injectedFn, null, 'extra')).toEqual('ret'); + expect(log).toEqual([null, 'self', 'arg0', 'extra']); }); it('should call injected function (as default)', async () => { @@ -76,10 +74,10 @@ describe('BaseInjector', () => { return 'ret'; } ); - expect(await hostInjector.invoke({ default: injectedFn } as any, null, 'extra')).to.eql( + expect(await hostInjector.invoke({ default: injectedFn } as any, null, 'extra')).toEqual( 'ret' ); - expect(log).to.eql([null, 'self', 'arg0', 'extra']); + expect(log).toEqual([null, 'self', 'arg0', 'extra']); }); it('should call injected method', async () => { @@ -94,8 +92,13 @@ describe('BaseInjector', () => { return 'ret'; } ); - expect(await hostInjector.invoke(injectedFn, null, 'arg2')).to.eql('ret'); - expect(log).to.eql([{ $host: fixture.host, $props: {}, $state: {} }, 'arg0', 'arg1', 'arg2']); + expect(await hostInjector.invoke(injectedFn, null, 'arg2')).toEqual('ret'); + expect(log).toEqual([ + { $host: fixture.host, $props: {}, $state: {} }, + 'arg0', + 'arg1', + 'arg2', + ]); }); it('should call injected method (as default)', async () => { @@ -110,11 +113,12 @@ describe('BaseInjector', () => { return 'ret'; } ); - expect(await hostInjector.invoke({ default: injectedFn } as any, null, 'arg2')).to.eql('ret'); - expect(log).to.eql([{ $host: fixture.host, $props: {}, $state: {} }, 'arg0', 'arg1', 'arg2']); + expect(await hostInjector.invoke({ default: injectedFn } as any, null, 'arg2')).toEqual('ret'); + expect(log).toEqual([{ $host: fixture.host, $props: {}, $state: {} }, 'arg0', 'arg1', 'arg2']); }); describe('error', async () => { + describe('error', () => { it('should include declare context when throwing error', async () => { fixture.host.setAttribute( AttributeMarker.ComponentTemplate, @@ -127,10 +131,10 @@ describe('BaseInjector', () => { ); try { await hostInjector.invoke(injectedFn, null, 'arg2'); - expect('should not get here').to.be.false; + expect('should not get here').toBe(false); } catch (e) { - expect(String(e)).to.contain('ProviderRejection'); - expect(e.stack).to.match(/DECLARED .*base_injector\.unit/); + expect(String(e)).toContain('ProviderRejection'); + expect(e.stack).toMatch(/DECLARED .*base_injector\.unit/); } }); }); @@ -143,13 +147,13 @@ describe('BaseInjector', () => { MyClass, // provideConst('arg0'), function (this: MyClass, arg0: string, arg1: string) { - expect(this).to.eql(myClass); - expect(arg0).to.eql('arg0'); - expect(arg1).to.eql('extra'); + expect(this).toEqual(myClass); + expect(arg0).toEqual('arg0'); + expect(arg1).toEqual('extra'); return 'ret'; } ); - expect(await hostInjector.invoke(injectedFn, myClass, 'extra')).to.eql('ret'); + expect(await hostInjector.invoke(injectedFn, myClass, 'extra')).toEqual('ret'); }); describe('error', () => { @@ -159,7 +163,7 @@ describe('BaseInjector', () => { MyClass, // function (this: MyClass) {} ); - expect(() => hostInjector.invoke(injectedFn, new WrongType())).to.throw( + expect(() => hostInjector.invoke(injectedFn, new WrongType())).toThrow( "INJECTOR-ERROR(Q-203): Expected injection 'this' to be of type 'MyClass', but was of type 'WrongType'." ); }); @@ -170,7 +174,7 @@ describe('BaseInjector', () => { fixture.host.setAttribute('prop-A', 'valueA'); fixture.host.setAttribute('bind:id:1', '$propB'); fixture.host.setAttribute('bind:id:2', '$propC;$prop-d'); - expect(hostInjector.elementProps).to.eql({ + expect(hostInjector.elementProps).toEqual({ propA: 'valueA', $propB: 'id:1', $propC: 'id:2', @@ -180,13 +184,13 @@ describe('BaseInjector', () => { describe('error', () => { it('should error if bind: without suffix', async () => { fixture.host.setAttribute('bind:', 'propA'); - expect(() => hostInjector.elementProps).to.throw( + expect(() => hostInjector.elementProps).toThrow( "COMPONENT-ERROR(Q-400): 'bind:' must have an key. (Example: 'bind:key=\"propertyName\"')." ); }); it('should error if bind: without content', () => { fixture.host.setAttribute('bind:id', ''); - expect(() => hostInjector.elementProps).to.throw( + expect(() => hostInjector.elementProps).toThrow( "COMPONENT-ERROR(Q-401): 'bind:id' must have a property name. (Example: 'bind:key=\"propertyName\"')." ); }); diff --git a/src/core/injector/element_injector.unit.ts b/src/core/injector/element_injector.unit.ts index bff070cb976..6ca5949ecc3 100644 --- a/src/core/injector/element_injector.unit.ts +++ b/src/core/injector/element_injector.unit.ts @@ -6,18 +6,16 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { Component } from '../component/component.js'; -import { TEST_CONFIG } from '../testing/config.unit.js'; -import type { EntityKey } from '../entity/entity_key.js'; -import { stringifyDebug } from '../error/stringify.js'; -import { QRL } from '../import/qrl.js'; -import { Entity, Injector } from '../index.js'; -import { serializeState } from '../render/serialize_state.js'; -import { Greeter, GreeterComponent, GreeterProps } from '../testing/component_fixture.js'; -import { ElementFixture } from '../testing/element_fixture.js'; -import { AttributeMarker } from '../util/markers.js'; -import { getClosestInjector, getInjector } from './element_injector.js'; +import { Component } from '../component/component'; +import { TEST_CONFIG } from '../util/test_config'; +import type { EntityKey } from '../entity/entity_key'; +import { stringifyDebug } from '../error/stringify'; +import { QRL } from '../import/qrl'; +import { Entity, Injector } from '../index'; +import { Greeter, GreeterComponent, GreeterProps } from '../util/test_component_fixture'; +import { ElementFixture, serializeState } from '@builder.io/qwik/testing'; +import { AttributeMarker } from '../util/markers'; +import { getClosestInjector, getInjector } from './element_injector'; describe('ElementInjector', () => { let fixture: ElementFixture; @@ -34,11 +32,11 @@ describe('ElementInjector', () => { GreeterComponent.$templateQRL as any ); const component = await hostInjector.getComponent(GreeterComponent); - expect(component).to.be.an.instanceOf(GreeterComponent); - expect(stringifyDebug(component.$host)).to.be.equal(stringifyDebug(fixture.host)); + expect(component).toBeInstanceOf(GreeterComponent); + expect(stringifyDebug(component.$host)).toEqual(stringifyDebug(fixture.host)); const component2 = await hostInjector.getComponent(GreeterComponent); - expect(component).to.eql(component2); + expect(component).toEqual(component2); }); it('should walk up the tree and find materialize component', async () => { fixture.superParent.setAttribute( @@ -46,8 +44,8 @@ describe('ElementInjector', () => { GreeterComponent.$templateQRL as any ); const component = await hostInjector.getComponent(GreeterComponent); - expect(component).to.be.an.instanceOf(GreeterComponent); - expect(stringifyDebug(component.$host)).to.be.equal(stringifyDebug(fixture.superParent)); + expect(component).toBeInstanceOf(GreeterComponent); + expect(stringifyDebug(component.$host)).toEqual(stringifyDebug(fixture.superParent)); }); it('should return the same promise instance', () => { fixture.superParent.setAttribute( @@ -56,7 +54,7 @@ describe('ElementInjector', () => { ); const component1 = hostInjector.getComponent(GreeterComponent); const component2 = hostInjector.getComponent(GreeterComponent); - expect(component1).to.equal(component2); + expect(component1).toEqual(component2); }); describe('state', () => { it('should materialize from attribute state', async () => { @@ -69,8 +67,8 @@ describe('ElementInjector', () => { JSON.stringify({ greeting: 'abc' }) ); const component = await hostInjector.getComponent(GreeterComponent); - expect(component.$state).to.eql({ greeting: 'abc' }); - expect(component.greeting).to.equal('abc'); + expect(component.$state).toEqual({ greeting: 'abc' }); + expect(component.greeting).toEqual('abc'); }); it('should materialize from $newState', async () => { fixture.host.setAttribute( @@ -80,9 +78,9 @@ describe('ElementInjector', () => { fixture.host.setAttribute('salutation', 'Hello'); fixture.host.setAttribute('name', 'World'); const component = await hostInjector.getComponent(GreeterComponent); - expect(component.$props).to.eql({ salutation: 'Hello', name: 'World' }); - expect(component.$state).to.eql({ greeting: 'Hello World!' }); - expect(component.greeting).to.equal('Hello World!'); + expect(component.$props).toEqual({ salutation: 'Hello', name: 'World' }); + expect(component.$state).toEqual({ greeting: 'Hello World!' }); + expect(component.greeting).toEqual('Hello World!'); }); it('should save state to attribute state', async () => { fixture.host.setAttribute( @@ -92,7 +90,7 @@ describe('ElementInjector', () => { const component = await hostInjector.getComponent(GreeterComponent); component.$state = { greeting: 'save me' }; serializeState(fixture.superParent); - expect(fixture.host.getAttribute(AttributeMarker.ComponentState)).to.eql( + expect(fixture.host.getAttribute(AttributeMarker.ComponentState)).toEqual( JSON.stringify({ greeting: 'save me' }) ); }); @@ -100,7 +98,7 @@ describe('ElementInjector', () => { describe('error', () => { it('should throw if component does not match', async () => { fixture.parent.setAttribute(AttributeMarker.ComponentTemplate, 'wrongQRL'); - expect(() => hostInjector.getComponent(GreeterComponent)).to.throw( + expect(() => hostInjector.getComponent(GreeterComponent)).toThrow( "COMPONENT-ERROR(Q-405): Unable to find 'GreeterComponent' component." ); }); @@ -110,13 +108,13 @@ describe('ElementInjector', () => { GreeterComponent.$templateQRL as any ); await hostInjector.getComponent(GreeterComponent); - expect(() => hostInjector.getComponent(GreeterShadowComponent)).to.throw( + expect(() => hostInjector.getComponent(GreeterShadowComponent)).toThrow( "COMPONENT-ERROR(Q-406): Requesting component 'GreeterShadowComponent' does not match existing component 'GreeterComponent'. Verify that the two components have distinct '$templateQRL's." ); }); it('should throw if two components is missing $templateQRL', async () => { class MissingQRL {} - expect(() => hostInjector.getComponent(MissingQRL as any)).to.throw( + expect(() => hostInjector.getComponent(MissingQRL as any)).toThrow( "COMPONENT-ERROR(Q-407): Expecting Component 'MissingQRL' to have static '$templateQRL' property, but none was found." ); }); @@ -130,7 +128,7 @@ describe('ElementInjector', () => { 'regards:-hello:-world', JSON.stringify({ greeting: 'serialized' }) ); - expect(await hostInjector.getEntityState('regards:-hello:-world')).to.eql({ + expect(await hostInjector.getEntityState('regards:-hello:-world')).toEqual({ $key: 'regards:-hello:-world', greeting: 'serialized', }); @@ -138,20 +136,20 @@ describe('ElementInjector', () => { // without the entity QRL. RegardsEntity.$attachEntity(fixture.host); const entity = await hostInjector.getEntity(regardsKey); - expect(entity.$key).to.eql('regards:-hello:-world'); - expect(entity.$props).to.eql({ salutation: 'Hello', name: 'World' }); - expect(entity.$state).to.eql({ + expect(entity.$key).toEqual('regards:-hello:-world'); + expect(entity.$props).toEqual({ salutation: 'Hello', name: 'World' }); + expect(entity.$state).toEqual({ $key: 'regards:-hello:-world', greeting: 'serialized', }); - expect(entity.greeting).to.equal('serialized'); + expect(entity.greeting).toEqual('serialized'); }); it('should retrieve entity by key from parent element', async () => { fixture.parent.setAttribute( 'regards:-hello:-world', JSON.stringify({ greeting: 'serialized' }) ); - expect(await hostInjector.getEntityState('regards:-hello:-world')).to.eql({ + expect(await hostInjector.getEntityState('regards:-hello:-world')).toEqual({ $key: 'regards:-hello:-world', greeting: 'serialized', }); @@ -159,9 +157,9 @@ describe('ElementInjector', () => { // without the entity QRL. RegardsEntity.$attachEntity(fixture.parent); const entity = await hostInjector.getEntity(regardsKey); - expect(entity.$key).to.eql('regards:-hello:-world'); - expect(entity.$props).to.eql({ salutation: 'Hello', name: 'World' }); - expect(entity.$state).to.eql({ + expect(entity.$key).toEqual('regards:-hello:-world'); + expect(entity.$props).toEqual({ salutation: 'Hello', name: 'World' }); + expect(entity.$state).toEqual({ $key: 'regards:-hello:-world', greeting: 'serialized', }); @@ -169,9 +167,9 @@ describe('ElementInjector', () => { it('should retrieve entity by key and call $newState', async () => { RegardsEntity.$attachEntity(fixture.parent); const entity = await hostInjector.getEntity(regardsKey); - expect(entity.$key).to.eql('regards:-hello:-world'); - expect(entity.$props).to.eql({ salutation: 'Hello', name: 'World' }); - expect(entity.$state).to.eql({ + expect(entity.$key).toEqual('regards:-hello:-world'); + expect(entity.$props).toEqual({ salutation: 'Hello', name: 'World' }); + expect(entity.$state).toEqual({ $key: 'regards:-hello:-world', greeting: 'Hello World!', }); @@ -180,7 +178,7 @@ describe('ElementInjector', () => { RegardsEntity.$attachEntity(fixture.parent); const entity1 = hostInjector.getEntity(regardsKey); const entity2 = hostInjector.getEntity(regardsKey); - expect(entity1).to.equal(entity2); + expect(entity1).toEqual(entity2); }); it('should retrieve the same instance of entity state', async () => { const state = { greeting: 'saved greeting' }; @@ -189,24 +187,24 @@ describe('ElementInjector', () => { { salutation: 'Hello', name: 'World' }, state ).$key; - expect(fixture.host.hasAttribute(String(key))).to.be.true; + expect(fixture.host.hasAttribute(String(key))).toBe(true); const entityState = await hostInjector.getEntityState(key); - expect(entityState).to.equal(state); + expect(entityState).toEqual(state); }); describe('error', () => { it('should throw error if no state define', () => { - expect(() => hostInjector.getEntityState('not:found')).to.throw( + expect(() => hostInjector.getEntityState('not:found')).toThrow( "ERROR(Q-004): Could not find entity state 'not:found' ( or entity provider '::not') at '' or any of it's parents." ); }); it('should throw error if entity state was not serialized', async () => { fixture.host.setAttribute('entity:1', ''); - expect(() => hostInjector.getEntityState('entity:1')).to.throw( + expect(() => hostInjector.getEntityState('entity:1')).toThrow( "INJECTOR-ERROR(Q-204): Entity key 'entity:1' is found on '' but does not contain state. Was 'serializeState()' not run during dehydration?" ); }); it('should throw error if no entity provider define', () => { - expect(() => hostInjector.getEntity('not:found' as any as EntityKey)).to.throw( + expect(() => hostInjector.getEntity('not:found' as any as EntityKey)).toThrow( "ERROR(Q-004): Could not find entity state 'not:found' ( or entity provider '::not') at '' or any of it's parents." ); }); @@ -216,7 +214,7 @@ describe('ElementInjector', () => { describe('getClosestInjector', () => { describe('error', () => { it('should throw when no parent injector fond', () => { - expect(() => getClosestInjector(fixture.parent)).to.throw( + expect(() => getClosestInjector(fixture.parent)).toThrow( "INJECTOR-ERROR(Q-206): No injector can be found starting at ''." ); }); diff --git a/src/core/injector/get_injector.unit.ts b/src/core/injector/get_injector.unit.ts index b7269b20331..6720a556814 100644 --- a/src/core/injector/get_injector.unit.ts +++ b/src/core/injector/get_injector.unit.ts @@ -6,26 +6,24 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { ElementFixture } from '../testing/element_fixture.js'; -import '../util/qDev.js'; -import { getInjector } from './element_injector.js'; +import { ElementFixture } from '@builder.io/qwik/testing'; +import { getInjector } from './element_injector'; describe('getInjector', () => { let fixture: ElementFixture; beforeEach(() => (fixture = new ElementFixture())); it('should throw if element not passed in', () => { - expect(() => getInjector(null!)).to.throw( + expect(() => getInjector(null!)).toThrow( "INJECTOR-ERROR(Q-202): Expected 'Element' was 'null'." ); }); it('should return no injector', () => { const hostInjector = getInjector(fixture.host, false); - expect(hostInjector).to.equal(null); + expect(hostInjector).toEqual(null); }); it('should create injector', () => { const injector = getInjector(fixture.host); - expect(injector.element).to.equal(fixture.host); - expect(fixture.host.getAttribute(':')).to.eql(''); + expect(injector.element).toEqual(fixture.host); + expect(fixture.host.getAttribute(':')).toEqual(''); }); }); diff --git a/src/core/injector/inject.unit.ts b/src/core/injector/inject.unit.ts index 20f06185f88..046fa8ccd68 100644 --- a/src/core/injector/inject.unit.ts +++ b/src/core/injector/inject.unit.ts @@ -6,16 +6,13 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { injectEventHandler } from '../event/inject_event_handler.js'; -import type { QRL } from '../import/qrl.js'; -import { ElementFixture } from '../testing/element_fixture.js'; -import '../testing/node_utils.js'; -import { createGlobal } from '../testing/node_utils.js'; -import { AttributeMarker } from '../util/markers.js'; -import { getInjector } from './element_injector.js'; -import { injectFunction } from './inject.js'; -import type { Injector } from './types.js'; +import { injectEventHandler } from '../event/inject_event_handler'; +import type { QRL } from '../import/qrl'; +import { createGlobal, ElementFixture } from '@builder.io/qwik/testing'; +import { AttributeMarker } from '../util/markers'; +import { getInjector } from './element_injector'; +import { injectFunction } from './inject'; +import type { Injector } from './types'; describe('inject', () => { const log: string[] = []; @@ -31,7 +28,7 @@ describe('inject', () => { it('should inject nothing', async () => { const injectedFn = injectFunction(() => log.push('invoked')); await injector.invoke(injectedFn); - expect(log).to.eql(['invoked']); + expect(log).toEqual(['invoked']); }); it('should inject this', async () => { @@ -42,8 +39,8 @@ describe('inject', () => { return 'return value'; } ); - expect(await injector.invoke(injectedFn)).to.equal('return value'); - expect(log).to.eql([undefined, 'arg0', 'invoked']); + expect(await injector.invoke(injectedFn)).toEqual('return value'); + expect(log).toEqual([undefined, 'arg0', 'invoked']); }); it('should inject async', async () => { @@ -54,12 +51,12 @@ describe('inject', () => { return Promise.resolve('return value'); } ); - expect(await injector.invoke(injectedFn)).to.equal('return value'); - expect(log).to.eql(['value', 'invoked']); + expect(await injector.invoke(injectedFn)).toEqual('return value'); + expect(log).toEqual(['value', 'invoked']); }); }); -describe('injectEventHandler', async () => { +describe('injectEventHandler', () => { const log: any[] = []; beforeEach(() => (log.length = 0)); @@ -84,7 +81,7 @@ describe('injectEventHandler', async () => { const fixture = new ElementFixture(); const url: URL = new URL('file:///somepath'); fixture.host.setAttribute(AttributeMarker.ComponentTemplate, './comp'); - expect(await injectedFn(fixture.host, event, url)).to.equal('return value'); - expect(log).to.eql([myComp, 'invoked', 'arg0']); + expect(await injectedFn(fixture.host, event, url)).toEqual('return value'); + expect(log).toEqual([myComp, 'invoked', 'arg0']); }); }); diff --git a/src/core/injector/provide_injector.unit.ts b/src/core/injector/provide_injector.unit.ts index 63434696b90..506c894d0f9 100644 --- a/src/core/injector/provide_injector.unit.ts +++ b/src/core/injector/provide_injector.unit.ts @@ -6,13 +6,12 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { provideInjector } from './provide_injector.js'; -import type { Injector } from './types.js'; +import { provideInjector } from './provide_injector'; +import type { Injector } from './types'; describe('provideInjector', () => { it('should return an injector', async () => { const injector: Injector = {} as any; - expect(await provideInjector()(injector)).to.equal(injector); + expect(await provideInjector()(injector)).toEqual(injector); }); }); diff --git a/src/core/injector/provide_provider_of.unit.ts b/src/core/injector/provide_provider_of.unit.ts index aff4a50d707..4e67dea07c3 100644 --- a/src/core/injector/provide_provider_of.unit.ts +++ b/src/core/injector/provide_provider_of.unit.ts @@ -6,15 +6,14 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { provideProviderOf } from './provide_provider_of.js'; -import type { Injector } from './types.js'; +import { provideProviderOf } from './provide_provider_of'; +import type { Injector } from './types'; describe('provideProviderOf', () => { it('should Provider', async () => { const injector: Injector = {} as any; const obj = {}; const objProvider = await provideProviderOf((injector: Injector) => [injector, obj])(injector); - expect(await objProvider()).to.eql([injector, obj]); + expect(await objProvider()).toEqual([injector, obj]); }); }); diff --git a/src/core/injector/resolve_args.unit.ts b/src/core/injector/resolve_args.unit.ts index 144aee4a83e..799bc7ca0a4 100644 --- a/src/core/injector/resolve_args.unit.ts +++ b/src/core/injector/resolve_args.unit.ts @@ -6,20 +6,18 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import '../testing/node_utils.js'; -import { resolveArgs } from './resolve_args.js'; -import type { Injector } from './types.js'; +import { resolveArgs } from './resolve_args'; +import type { Injector } from './types'; describe('resolveArgs', () => { it('should return values', async () => { const injector = null!; // not needed because no providers requested. - expect(await resolveArgs(injector, 1, 2)).to.eql([1, 2]); + expect(await resolveArgs(injector, 1, 2)).toEqual([1, 2]); }); it('should resolve promise values', async () => { const injector = {}! as any as Injector; // not needed because no providers requested. expect( await resolveArgs(injector, 1, (injector: Injector) => Promise.resolve(injector)) - ).to.eql([1, injector]); + ).toEqual([1, injector]); }); }); diff --git a/src/core/provider/provide_component_prop.unit.ts b/src/core/provider/provide_component_prop.unit.ts index 900696ea19c..46e2364ff9c 100644 --- a/src/core/provider/provide_component_prop.unit.ts +++ b/src/core/provider/provide_component_prop.unit.ts @@ -6,10 +6,9 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { getInjector } from '../injector/element_injector.js'; -import { ComponentFixture } from '../testing/component_fixture.js'; -import { provideComponentProp } from './provide_component_prop.js'; +import { getInjector } from '../injector/element_injector'; +import { ComponentFixture } from '@builder.io/qwik/testing'; +import { provideComponentProp } from './provide_component_prop'; describe('getComponentProps', () => { let fixture: ComponentFixture; @@ -23,16 +22,16 @@ describe('getComponentProps', () => { fixture.host.setAttribute('bind:id:2', '$propC;$propD'); const injector = getInjector(fixture.host); - expect(provideComponentProp('propA')(injector)).to.equal('valueA'); - expect(provideComponentProp('$propB')(injector)).to.equal('id:1'); - expect(provideComponentProp('$propC')(injector)).to.equal('id:2'); - expect(provideComponentProp('$propD')(injector)).to.equal('id:2'); + expect(provideComponentProp('propA')(injector)).toEqual('valueA'); + expect(provideComponentProp('$propB')(injector)).toEqual('id:1'); + expect(provideComponentProp('$propC')(injector)).toEqual('id:2'); + expect(provideComponentProp('$propD')(injector)).toEqual('id:2'); }); describe('error', () => { it('should throw if property not defined', () => { const injector = getInjector(fixture.host); - expect(() => provideComponentProp('propA')(injector)).to.throw( + expect(() => provideComponentProp('propA')(injector)).toThrow( "COMPONENT-ERROR(Q-404): Property 'propA' not found in '{}' on component ''." ); }); diff --git a/src/core/provider/provide_component_props.unit.ts b/src/core/provider/provide_component_props.unit.ts index 4f768bafccd..514a4265087 100644 --- a/src/core/provider/provide_component_props.unit.ts +++ b/src/core/provider/provide_component_props.unit.ts @@ -6,11 +6,10 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { getInjector } from '../injector/element_injector.js'; -import { injectFunction } from '../injector/inject.js'; -import { ComponentFixture } from '../testing/component_fixture.js'; -import { provideComponentProps } from './provide_component_props.js'; +import { getInjector } from '../injector/element_injector'; +import { injectFunction } from '../injector/inject'; +import { ComponentFixture } from '@builder.io/qwik/testing'; +import { provideComponentProps } from './provide_component_props'; describe('provideComponentState', () => { it('should inject empty state', async () => { @@ -21,6 +20,6 @@ describe('provideComponentState', () => { fixture.host.setAttribute('salutation', 'Hello'); const injector = getInjector(fixture.host); - expect(await injector.invoke(handler)).to.eql({ salutation: 'Hello' }); + expect(await injector.invoke(handler)).toEqual({ salutation: 'Hello' }); }); }); diff --git a/src/core/provider/provide_component_state.unit.ts b/src/core/provider/provide_component_state.unit.ts index ecf76498af9..ea2baadc49e 100644 --- a/src/core/provider/provide_component_state.unit.ts +++ b/src/core/provider/provide_component_state.unit.ts @@ -6,27 +6,26 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { ComponentFixture } from '../testing/component_fixture.js'; -import { provideComponentState } from './provide_component_state.js'; +import { ComponentFixture } from '@builder.io/qwik/testing'; +import { provideComponentState } from './provide_component_state'; describe('provideComponentState', () => { it('should return undefined if no state defined', () => { const fixture = new ComponentFixture(); - expect(provideComponentState(false)(fixture.injector)).to.equal(undefined); + expect(provideComponentState(false)(fixture.injector)).toEqual(undefined); }); it('should return state', () => { const fixture = new ComponentFixture(); fixture.host.setAttribute(':.', JSON.stringify({ value: 'worked' })); - expect(provideComponentState(false)(fixture.injector)).to.eql({ + expect(provideComponentState(false)(fixture.injector)).toEqual({ value: 'worked', }); }); it('should inject empty state', () => { const fixture = new ComponentFixture(); - expect(() => provideComponentState()(fixture.injector)).to.throw( + expect(() => provideComponentState()(fixture.injector)).toThrow( "Can't find state on host element." ); }); @@ -36,6 +35,6 @@ describe('provideComponentState', () => { const state = { prop: 'value' }; fixture.host.setAttribute('::', './qrl'); fixture.host.setAttribute(':.', JSON.stringify(state)); - expect(provideComponentState()(fixture.injector)).to.eql(state); + expect(provideComponentState()(fixture.injector)).toEqual(state); }); }); diff --git a/src/core/provider/provide_entity.unit.ts b/src/core/provider/provide_entity.unit.ts index 9f215164f69..32cd30200da 100644 --- a/src/core/provider/provide_entity.unit.ts +++ b/src/core/provider/provide_entity.unit.ts @@ -6,16 +6,15 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { TEST_CONFIG } from '../testing/config.unit.js'; -import { Entity } from '../entity/entity.js'; -import type { EntityKey } from '../entity/entity_key.js'; -import { QRL } from '../import/qrl.js'; -import { getInjector } from '../injector/element_injector.js'; -import { injectFunction } from '../injector/inject.js'; -import type { Injector, Provider } from '../injector/types.js'; -import { ElementFixture } from '../testing/element_fixture.js'; -import { provideEntity } from './provide_entity.js'; +import { TEST_CONFIG } from '../util/test_config'; +import { Entity } from '../entity/entity'; +import type { EntityKey } from '../entity/entity_key'; +import { QRL } from '../import/qrl'; +import { getInjector } from '../injector/element_injector'; +import { injectFunction } from '../injector/inject'; +import type { Injector, Provider } from '../injector/types'; +import { ElementFixture } from '@builder.io/qwik/testing'; +import { provideEntity } from './provide_entity'; describe('provideEntity', () => { let fixture: ElementFixture; @@ -34,7 +33,7 @@ describe('provideEntity', () => { (entity: RegardsEntity) => entity ); - expect((await hostInjector.invoke(fn)).$state).to.eql({ + expect((await hostInjector.invoke(fn)).$state).toEqual({ $key: 'regards:Hello:World', greeting: 'Hello World!', }); diff --git a/src/core/provider/provide_entity_state.unit.ts b/src/core/provider/provide_entity_state.unit.ts index 6a0147aa2b5..dfc901fecc3 100644 --- a/src/core/provider/provide_entity_state.unit.ts +++ b/src/core/provider/provide_entity_state.unit.ts @@ -6,17 +6,16 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { TEST_CONFIG } from '../testing/config.unit.js'; -import { Entity } from '../entity/entity.js'; -import type { EntityKey } from '../entity/entity_key.js'; -import { QRL } from '../import/qrl.js'; -import { getInjector } from '../injector/element_injector.js'; -import type { Injector } from '../injector/index.js'; -import { injectFunction } from '../injector/inject.js'; +import { TEST_CONFIG } from '../util/test_config'; +import { Entity } from '../entity/entity'; +import type { EntityKey } from '../entity/entity_key'; +import { QRL } from '../import/qrl'; +import { getInjector } from '../injector/element_injector'; +import type { Injector } from '../injector/index'; +import { injectFunction } from '../injector/inject'; import type { Provider } from '../injector/types'; -import { ElementFixture } from '../testing/element_fixture.js'; -import { provideEntityState } from './provide_entity_state.js'; +import { ElementFixture } from '@builder.io/qwik/testing'; +import { provideEntityState } from './provide_entity_state'; describe('provideEntity', () => { let fixture: ElementFixture; @@ -34,7 +33,7 @@ describe('provideEntity', () => { (entity: Regards) => entity ); - expect(await hostInjector.invoke(fn)).to.eql({ + expect(await hostInjector.invoke(fn)).toEqual({ $key: 'regards:Hello:World', greeting: 'Hello World!', }); diff --git a/src/core/render/jsx/attributes.unit.tsx b/src/core/render/jsx/attributes.unit.tsx index b3a0611112a..854f5a32f13 100644 --- a/src/core/render/jsx/attributes.unit.tsx +++ b/src/core/render/jsx/attributes.unit.tsx @@ -6,73 +6,69 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { stringifyDebug } from '../../error/stringify.js'; -import { ComponentFixture } from '../../testing/component_fixture.js'; -import { ElementFixture } from '../../testing/element_fixture.js'; -import { createGlobal } from '../../testing/node_utils.js'; -import { applyAttributes, setAttribute, stringifyClassOrStyle } from './attributes.js'; -import { jsxFactory } from './factory.js'; +import { h } from '@builder.io/qwik'; +import { stringifyDebug } from '../../error/stringify'; +import { createDocument, ComponentFixture, ElementFixture } from '@builder.io/qwik/testing'; +import { applyAttributes, setAttribute, stringifyClassOrStyle } from './attributes'; -const _needed_by_JSX_ = jsxFactory; // eslint-disable-line @typescript-eslint/no-unused-vars describe('attributes', () => { let host: HTMLElement; let input: HTMLInputElement; beforeEach(() => { - const global = createGlobal(); - host = global.document.createElement('host'); - input = global.document.createElement('input'); + const doc = createDocument(); + host = doc.createElement('host'); + input = doc.createElement('input'); }); describe('applyAttributes()', () => { it('should do nothing', () => { - expect(applyAttributes(host, null, false)).to.be.false; - expect(applyAttributes(host, null, true)).to.be.false; - expect(applyAttributes(host, {}, false)).to.be.false; - expect(applyAttributes(host, {}, true)).to.be.false; + expect(applyAttributes(host, null, false)).toBe(false); + expect(applyAttributes(host, null, true)).toBe(false); + expect(applyAttributes(host, {}, false)).toBe(false); + expect(applyAttributes(host, {}, true)).toBe(false); }); it('should apply properties to Element', () => { - expect(applyAttributes(host, { a: 'b' }, false)).to.be.false; - expect(host.outerHTML).to.equal(''); - expect(applyAttributes(host, { a: 'b' }, true)).to.be.false; - expect(host.outerHTML).to.equal(''); - expect(applyAttributes(host, { a: 'c' }, true)).to.be.true; - expect(host.outerHTML).to.equal(''); + expect(applyAttributes(host, { a: 'b' }, false)).toBe(false); + expect(host.outerHTML).toEqual(''); + expect(applyAttributes(host, { a: 'b' }, true)).toBe(false); + expect(host.outerHTML).toEqual(''); + expect(applyAttributes(host, { a: 'c' }, true)).toBe(true); + expect(host.outerHTML).toEqual(''); }); it('should remove properties from Element', () => { - expect(applyAttributes(host, { a: '' }, false)).to.be.false; - expect(host.outerHTML).to.equal(''); - expect(applyAttributes(host, { a: '' }, true)).to.be.false; - expect(host.outerHTML).to.equal(''); - expect(applyAttributes(host, { a: null! }, true)).to.be.true; - expect(host.outerHTML).to.equal(''); - expect(applyAttributes(host, { a: undefined! }, true)).to.be.true; - expect(host.outerHTML).to.equal(''); + expect(applyAttributes(host, { a: '' }, false)).toBe(false); + expect(host.outerHTML).toEqual(''); + expect(applyAttributes(host, { a: '' }, true)).toBe(false); + expect(host.outerHTML).toEqual(''); + expect(applyAttributes(host, { a: null! }, true)).toBe(true); + expect(host.outerHTML).toEqual(''); + expect(applyAttributes(host, { a: undefined! }, true)).toBe(true); + expect(host.outerHTML).toEqual(''); }); describe('to input elements', () => { it('should write both attribute and `value` property', () => { - expect(applyAttributes(input, { value: 'hello' }, false)).to.be.false; - expect(input.value).to.eql('hello'); - expect(input.getAttribute('value')).to.eql('hello'); + expect(applyAttributes(input, { value: 'hello' }, false)).toBe(false); + expect(input.value).toEqual('hello'); + expect(input.getAttribute('value')).toEqual('hello'); - expect(applyAttributes(input, { value: 'bar' }, false)).to.be.false; - expect(input.value).to.eql('bar'); - expect(input.getAttribute('value')).to.eql('bar'); + expect(applyAttributes(input, { value: 'bar' }, false)).toBe(false); + expect(input.value).toEqual('bar'); + expect(input.getAttribute('value')).toEqual('bar'); input.value = 'baz'; - expect(applyAttributes(input, { value: 'hello' }, false)).to.be.false; - expect(input.value).to.eql('hello'); - expect(input.getAttribute('value')).to.eql('hello'); + expect(applyAttributes(input, { value: 'hello' }, false)).toBe(false); + expect(input.value).toEqual('hello'); + expect(input.getAttribute('value')).toEqual('hello'); }); }); describe('innerHTML', () => { it('should deal with innerHTML', () => { - expect(applyAttributes(host, { innerHTML: '
text
' }, false)).to.be.false; - expect(host.outerHTML).to.equal('
text
'); + expect(applyAttributes(host, { innerHTML: '
text
' }, false)).toBe(false); + expect(host.outerHTML).toEqual('
text
'); }); }); @@ -80,23 +76,22 @@ describe('attributes', () => { it('should render $ binding', async () => { const fixture = new ComponentFixture(); let myValue: string | null = 'someItem:123:child:432'; +
; fixture.template = () => { return ; }; await fixture.render(); - expect(fixture.host.innerHTML).to.equal( + expect(fixture.host.innerHTML).toEqual( '' ); myValue = 'otherItem'; await fixture.render(); - expect(fixture.host.innerHTML).to.equal( + expect(fixture.host.innerHTML).toEqual( '' ); myValue = null; await fixture.render(); - expect(fixture.host.innerHTML).to.equal( - '' - ); + expect(fixture.host.innerHTML).toEqual(''); }); it('should merge bindings', async () => { @@ -107,37 +102,37 @@ describe('attributes', () => { return ; }; await fixture.render(); - expect(fixture.host.innerHTML).to.equal( + expect(fixture.host.innerHTML).toEqual( '' ); value1 = 'same'; value2 = 'same'; await fixture.render(); - expect(fixture.host.innerHTML).to.equal( + expect(fixture.host.innerHTML).toEqual( '' ); value1 = null; value2 = null; await fixture.render(); - expect(fixture.host.innerHTML).to.equal( + expect(fixture.host.innerHTML).toEqual( '' ); }); it('should detect binding change', async () => { const fixture = new ComponentFixture(); - expect(applyAttributes(fixture.host, { $propA: 'item:1' }, true)).to.be.true; - expect(stringifyDebug(fixture.host)).to.eql( + expect(applyAttributes(fixture.host, { $propA: 'item:1' }, true)).toBe(true); + expect(stringifyDebug(fixture.host)).toEqual( `` ); - expect(applyAttributes(fixture.host, { $propA: 'item:1' }, true)).to.be.false; - expect(stringifyDebug(fixture.host)).to.eql( + expect(applyAttributes(fixture.host, { $propA: 'item:1' }, true)).toBe(false); + expect(stringifyDebug(fixture.host)).toEqual( `` ); - expect(applyAttributes(fixture.host, { $propA: 'item:2' }, true)).to.be.true; - expect(stringifyDebug(fixture.host)).to.eql( + expect(applyAttributes(fixture.host, { $propA: 'item:2' }, true)).toBe(true); + expect(stringifyDebug(fixture.host)).toEqual( `` ); }); @@ -153,7 +148,7 @@ describe('attributes', () => { }, false ); - expect(host.getAttribute('on:click')).to.eql('url'); + expect(host.getAttribute('on:click')).toEqual('url'); }); it('should apply on:* properties with camelCase', () => { @@ -164,7 +159,7 @@ describe('attributes', () => { }, false ); - expect(host.getAttribute('on:camel-case')).to.eql('url'); + expect(host.getAttribute('on:camel-case')).toEqual('url'); }); it('should apply all entity bindings', () => { @@ -181,7 +176,7 @@ describe('attributes', () => { }, false ); - expect(host.getAttribute('::entity')).to.eql('url'); + expect(host.getAttribute('::entity')).toEqual('url'); }); describe('error', () => { @@ -194,7 +189,7 @@ describe('attributes', () => { }, false ) - ).to.throw(`RENDER-ERROR(Q-603): Expecting array of entities, got 'notAnArray'.`); + ).toThrow(`RENDER-ERROR(Q-603): Expecting array of entities, got 'notAnArray'.`); }); it('should error if a entity does not have $attachEntity', () => { expect(() => @@ -205,26 +200,26 @@ describe('attributes', () => { }, false ) - ).to.throw(`RENDER-ERROR(Q-602): Expecting entity object, got '{"notEntity":true}'.`); + ).toThrow(`RENDER-ERROR(Q-602): Expecting entity object, got '{"notEntity":true}'.`); }); }); }); describe('stringifyClassOrStyle', () => { it('should return string', () => { - expect(stringifyClassOrStyle('value', true)).to.eql('value'); - expect(stringifyClassOrStyle(null!, true)).to.eql(''); + expect(stringifyClassOrStyle('value', true)).toEqual('value'); + expect(stringifyClassOrStyle(null!, true)).toEqual(''); }); it('should turn into class', () => { - expect(stringifyClassOrStyle(['a', 'b'], true)).to.eql('a b'); - expect(stringifyClassOrStyle({ a: true, b: false }, true)).to.eql('a'); + expect(stringifyClassOrStyle(['a', 'b'], true)).toEqual('a b'); + expect(stringifyClassOrStyle({ a: true, b: false }, true)).toEqual('a'); }); it('should turn into style', () => { - expect(stringifyClassOrStyle({ a: true, b: false }, false)).to.eql('a:true;b:false'); + expect(stringifyClassOrStyle({ a: true, b: false }, false)).toEqual('a:true;b:false'); }); describe('error', () => { it('should complain on setting array on style', () => { - expect(() => stringifyClassOrStyle(['a', 'b'], false)).to.throw( + expect(() => stringifyClassOrStyle(['a', 'b'], false)).toThrow( `RENDER-ERROR(Q-601): Value '["a","b"]' can't be written into 'style' attribute.` ); }); @@ -238,30 +233,30 @@ describe('attributes', () => { it('should set/remove attribute', () => { setAttribute(fixture.host, 'id', 'value'); - expect(fixture.host.getAttribute('id')).to.eql('value'); + expect(fixture.host.getAttribute('id')).toEqual('value'); setAttribute(fixture.host, 'id', null); - expect(fixture.host.hasAttribute('id')).to.be.false; + expect(fixture.host.hasAttribute('id')).toBe(false); }); it('should set class', () => { setAttribute(fixture.host, 'class', ['a', 'b']); - expect(fixture.host.getAttribute('class')).to.eql('a b'); + expect(fixture.host.getAttribute('class')).toEqual('a b'); }); it('should set style', () => { setAttribute(fixture.host, 'style', { color: 'red', width: '10px' }); - expect(fixture.host.getAttribute('style')).to.eql('color:red;width:10px'); + expect(fixture.host.getAttribute('style')).toEqual('color:red;width:10px'); }); it('should set INPUT properties', () => { fixture.host.setAttribute('value', 'initial'); setAttribute(fixture.host, 'value', 'update'); - expect((fixture.host as HTMLInputElement).value).to.equal('update'); + expect((fixture.host as HTMLInputElement).value).toEqual('update'); }); describe('error', () => { it('should complain on setting array on style', () => { - expect(() => setAttribute(fixture.host, 'style', ['a', 'b'])).to.throw( + expect(() => setAttribute(fixture.host, 'style', ['a', 'b'])).toThrow( `RENDER-ERROR(Q-601): Value '["a","b"]' can't be written into 'style' attribute.` ); }); diff --git a/src/core/render/jsx/mark_dirty.unit.ts b/src/core/render/jsx/mark_dirty.unit.ts index 1af87fc9fa4..56130ca5a98 100644 --- a/src/core/render/jsx/mark_dirty.unit.ts +++ b/src/core/render/jsx/mark_dirty.unit.ts @@ -6,33 +6,29 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { stringifyDebug } from '../../error/stringify.js'; -import { GreeterComponent, PersonEntity } from '../../testing/component_fixture.js'; -import { ElementFixture } from '../../testing/element_fixture.js'; -import type { MockRequestAnimationFrame } from '../../testing/node_utils.js'; -import { AttributeMarker } from '../../util/markers.js'; -import { markDirty, markEntityDirty, scheduleRender, toAttrQuery } from './mark_dirty.js'; +import { stringifyDebug } from '../../error/stringify'; +import { GreeterComponent, PersonEntity } from '../../util/test_component_fixture'; +import { ElementFixture, MockDocument, getTestPlatform } from '@builder.io/qwik/testing'; +import { AttributeMarker } from '../../util/markers'; +import { markDirty, markEntityDirty, scheduleRender, toAttrQuery } from './mark_dirty'; describe('mark_dirty', () => { let host: HTMLElement; - let window: Window; - let document: Document; + let doc: MockDocument; let fixture: ElementFixture; let greeterComponent: GreeterComponent; beforeEach(async () => { fixture = new ElementFixture(); host = fixture.host; - document = host.ownerDocument; - window = document.defaultView!; + doc = fixture.document; greeterComponent = await GreeterComponent.$new(fixture.host); }); describe('markComponentDirty', () => { - it('should schedule rAF and return list of components', async () => { + it('should schedule render and return list of components', async () => { const elementsPromise = markDirty(greeterComponent); - (window.requestAnimationFrame as MockRequestAnimationFrame).flush(); - expect(stringifyDebug(await elementsPromise)).to.eql(stringifyDebug([fixture.host])); + await getTestPlatform(doc).flush(); + expect(stringifyDebug(await elementsPromise)).toEqual(stringifyDebug([fixture.host])); }); }); @@ -42,54 +38,46 @@ describe('mark_dirty', () => { first: 'First', last: 'Last', }); - expect(personService.$key).to.equal('person:-last:-first'); + expect(personService.$key).toEqual('person:-last:-first'); fixture.host.setAttribute(AttributeMarker.BindPrefix + personService.$key, 'personKey'); markDirty(personService); fixture.host.innerHTML = ''; - expect(fixture.host.innerHTML).to.equal(''); + expect(fixture.host.innerHTML).toEqual(''); fixture.host.setAttribute('salutation', 'Hello'); fixture.host.setAttribute('name', 'World'); const elementsPromise = markDirty(greeterComponent); - (window.requestAnimationFrame as MockRequestAnimationFrame).flush(); - expect(stringifyDebug(await elementsPromise)).to.eql(stringifyDebug([fixture.host])); - expect(fixture.host.innerHTML).to.equal('Hello World!'); + await getTestPlatform(doc).flush(); + expect(stringifyDebug(await elementsPromise)).toEqual(stringifyDebug([fixture.host])); + expect(fixture.host.innerHTML).toEqual('Hello World!'); }); }); describe('toAttrQuery', () => { it('should escape attrs', () => { - expect(toAttrQuery('a:b:123')).to.eql('[a\\:b\\:123]'); + expect(toAttrQuery('a:b:123')).toEqual('[a\\:b\\:123]'); }); }); describe('scheduleRender', () => { - it('should schedule rAF and return empty list of no render', async () => { - const elementsPromise = scheduleRender(document); - (window.requestAnimationFrame as MockRequestAnimationFrame).flush(); - expect(await elementsPromise).to.eql([]); + it('should schedule render and return empty list of no render', async () => { + const elementsPromise = scheduleRender(doc); + await getTestPlatform(doc).flush(); + expect(await elementsPromise).toEqual([]); }); - it('should schedule rAF and return list of components', async () => { - const elementsPromise = scheduleRender(document); + it('should schedule render and return list of components', async () => { + const elementsPromise = scheduleRender(doc); fixture.host.setAttribute(AttributeMarker.EventRender, ''); - (window.requestAnimationFrame as MockRequestAnimationFrame).flush(); - expect(stringifyDebug(await elementsPromise)).to.eql(stringifyDebug([fixture.host])); + await getTestPlatform(doc).flush(); + expect(stringifyDebug(await elementsPromise)).toEqual(stringifyDebug([fixture.host])); }); }); describe('error', () => { - beforeEach(() => { - window.requestAnimationFrame = null!; - }); it('should throw error if neither Component nor Entity', () => { - expect(() => markDirty({ mark: 'other' } as any)).to.throw( + expect(() => markDirty({ mark: 'other' } as any)).toThrow( `RENDER-ERROR(Q-604): Expecting Entity or Component got '{"mark":"other"}'.` ); }); - it('should throw error rAF is not available (server)', () => { - expect(() => scheduleRender(document)).to.throw( - "RENDER-ERROR(Q-605): 'requestAnimationFrame' not found. If you are running on server design your applications in a way which does not require 'requestAnimationFrame' on first render." - ); - }); it('should throw an error if bind:_ is not on a component', async () => { const personService = await PersonEntity.$hydrate(fixture.parent, { first: 'First', @@ -97,8 +85,8 @@ describe('mark_dirty', () => { }); host.setAttribute(AttributeMarker.BindPrefix + personService.$key, '$person'); host.removeAttribute(AttributeMarker.ComponentTemplate); - expect(() => markEntityDirty(personService)).to.throw( - `RENDER-ERROR(Q-606): Expecting that element with 'bind:person:-last:-first' should be a component (should have 'decl:template="qrl"' attribute): ` + expect(() => markEntityDirty(personService)).toThrow( + `RENDER-ERROR(Q-605): Expecting that element with 'bind:person:-last:-first' should be a component (should have 'decl:template="qrl"' attribute): ` ); }); }); diff --git a/src/core/render/jsx/render.unit.tsx b/src/core/render/jsx/render.unit.tsx index 08307eca302..0b6f0633fda 100644 --- a/src/core/render/jsx/render.unit.tsx +++ b/src/core/render/jsx/render.unit.tsx @@ -6,45 +6,42 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { TEST_CONFIG } from '../../testing/config.unit.js'; -import { QRL } from '../../import/qrl.js'; -import { ElementFixture, applyDocumentConfig } from '../../testing/element_fixture.js'; -import { createGlobal, QwikGlobal } from '../../testing/node_utils.js'; -import { jsxDeclareComponent, jsxFactory } from './factory.js'; -import { Host } from './host.js'; -import type { JSX_IntrinsicElements } from './html.js'; -import type { JSXBase } from './html_base.js'; -import { jsxRender } from './render.js'; - -const _needed_by_JSX_ = jsxFactory; // eslint-disable-line @typescript-eslint/no-unused-vars -const _needed_by_ide_: JSX_IntrinsicElements = null!; // eslint-disable-line @typescript-eslint/no-unused-vars +import { TEST_CONFIG } from '../../util/test_config'; +import { QRL } from '../../import/qrl'; +import { + ElementFixture, + applyDocumentConfig, + createDocument, + MockDocument, +} from '@builder.io/qwik/testing'; +import { jsxDeclareComponent, h } from './factory'; +import { jsx, Fragment } from './jsx-runtime'; +import { Host } from './host'; +import { jsxRender } from './render'; // TODO(test): add test where `` => `async function Foo` describe('render', () => { - let global: QwikGlobal; - let document: Document; + let doc: MockDocument; let host: HTMLElement; beforeEach(() => { - global = createGlobal(); - host = global.document.createElement('host'); - document = global.document; - applyDocumentConfig(document, TEST_CONFIG); + doc = createDocument(); + host = doc.createElement('host'); + applyDocumentConfig(doc, TEST_CONFIG); }); it('should render basic DOM structure', () => { jsxRender(host,
test
); - expect(host.innerHTML).to.equal('
test
'); + expect(host.innerHTML).toEqual('
test
'); }); it('should not destroy existing DOM', () => { jsxRender(host,
original
); const originalDiv = host.firstChild; jsxRender(host,
overwrite
); - expect(host.firstChild).to.equal(originalDiv, 'node identity should not be destroyed'); - expect(host.innerHTML).to.equal('
overwrite
'); + expect(host.firstChild).toEqual(originalDiv); + expect(host.innerHTML).toEqual('
overwrite
'); }); it('should remove extra text', () => { @@ -56,9 +53,9 @@ describe('render', () => { {'b'} ); - expect(host.innerHTML).to.equal('
ab
'); + expect(host.innerHTML).toEqual('
ab
'); jsxRender(host,
original
); - expect(host.innerHTML).to.equal('
original
'); + expect(host.innerHTML).toEqual('
original
'); }); it('should remove extra nodes', () => { @@ -70,7 +67,7 @@ describe('render', () => { ); jsxRender(host,
); - expect(host.innerHTML).to.equal('
'); + expect(host.innerHTML).toEqual('
'); jsxRender( host,
@@ -78,48 +75,30 @@ describe('render', () => {
); - expect(host.innerHTML).to.equal('
'); - }); - - it.skip('should render HEAD', () => { - // TODO, figure out how should render in this scenario - const head = document.querySelector('head')!; - jsxRender( - head, - - Hello World from Server - - - ); - - expect(head.outerHTML).to.equal( - '' + - '' + - 'Hello World from Server' + - '' + - '' + - '' - ); + expect(host.innerHTML).toEqual('
'); }); it('should render HTML on document', () => { const cmp = ( - Hello World from Server - + Hello World Testing! Hello World! ); - jsxRender(document, cmp); + jsxRender(doc, cmp); + + expect(doc.title).toBe('Hello World Testing!'); - const html = document.querySelector('html')!; - expect(html.outerHTML).to.equal( + const titleElm = doc.querySelector('title')!; + expect(titleElm.textContent).toBe('Hello World Testing!'); + + const html = doc.querySelector('html')!; + expect(html.outerHTML).toEqual( '' + '' + - 'Hello World from Server' + - '' + + 'Hello World Testing!' + '' + 'Hello World!' + '' @@ -137,7 +116,7 @@ describe('render', () => { ); - expect(host.innerHTML).to.equal( + expect(host.innerHTML).toEqual( '
' + '' + 'Hello World! (/)' + @@ -155,7 +134,7 @@ describe('render', () => { B ); - expect(host.innerHTML).to.equal('AB'); + expect(host.innerHTML).toEqual('AB'); }); it('should support fragment in root of component', () => { @@ -174,7 +153,7 @@ describe('render', () => {
); - expect(host.innerHTML).to.equal('
AB
'); + expect(host.innerHTML).toEqual('
AB
'); }); }); @@ -182,7 +161,7 @@ describe('render', () => { it('should be able to render innerHTML', async () => { const html = `TEST`; await jsxRender(host,
); - expect(host.innerHTML).to.equal('
TEST
'); + expect(host.innerHTML).toEqual('
TEST
'); }); }); @@ -194,7 +173,7 @@ describe('render', () => { ); - expect(host.innerHTML).to.equal( + expect(host.innerHTML).toEqual( '
' + '' + 'Hello World! (/)' + @@ -210,15 +189,15 @@ describe('render', () => { // Event prefixes `.` to mean framework event such as ` await jsxRender( host, - jsxFactory('div', { - 'decl:template': 'jsx:/render.unit#Noop_template', + jsx('div', { + 'decl:template': QRL`jsx:/render.unit#Noop_template`, 'bind:.': 'myUrl', 'on:.render': 'myComponentUrl', - 'on:click': 'myComponent_click', + 'on:click': QRL`myComponent_click`, 'bind:token': 'myTokenUrl', }) ); - expect(host.innerHTML).to.equal( + expect(host.innerHTML).toEqual( '
NOOP
' ); }); @@ -230,7 +209,7 @@ describe('render', () => { fixture.host.innerHTML = ''; fixture.host.setAttribute('parent', 'pValue'); await jsxRender(fixture.host, VIEW); - expect(fixture.host.outerHTML).to.eql(`VIEW`); + expect(fixture.host.outerHTML).toEqual(`VIEW`); }); describe('styling', () => { @@ -249,14 +228,6 @@ describe('render', () => { }); }); -declare global { - namespace JSX { - interface IntrinsicElements { - greeter: { url?: string } & JSXBase; - } - } -} - export function Greeter_render_with_url(props: { url?: string }) { return Hello World! ({props.url}); } diff --git a/src/core/render/serialize_state.unit.ts b/src/core/render/serialize_state.unit.ts deleted file mode 100644 index b5370ece9cb..00000000000 --- a/src/core/render/serialize_state.unit.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** - * @license - * Copyright Builder.io, Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE - */ diff --git a/src/core/util/attributes.unit.ts b/src/core/util/attributes.unit.ts index a603417656a..6e3c33c9754 100644 --- a/src/core/util/attributes.unit.ts +++ b/src/core/util/attributes.unit.ts @@ -6,9 +6,8 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { ElementFixture } from '../testing/element_fixture.js'; -import { extractPropsFromElement } from './attributes.js'; +import { ElementFixture } from '@builder.io/qwik/testing'; +import { extractPropsFromElement } from './attributes'; describe('attributes', () => { describe('extractPropsFromElement', () => { @@ -16,7 +15,7 @@ describe('attributes', () => { const fixture = new ElementFixture(); fixture.host.setAttribute('key', 'value'); fixture.host.setAttribute('name', 'Qwik'); - expect(extractPropsFromElement(fixture.host)).to.eql({ + expect(extractPropsFromElement(fixture.host)).toEqual({ key: 'value', name: 'Qwik', }); @@ -25,7 +24,7 @@ describe('attributes', () => { const fixture = new ElementFixture(); fixture.host.setAttribute('bind:value', '$key'); fixture.host.setAttribute('bind:value2', '$keyA;$keyB'); - expect(extractPropsFromElement(fixture.host)).to.eql({ + expect(extractPropsFromElement(fixture.host)).toEqual({ $key: 'value', $keyA: 'value2', $keyB: 'value2', @@ -37,21 +36,21 @@ describe('attributes', () => { fixture.host.setAttribute(':bar', ''); fixture.host.setAttribute('foo:', ''); fixture.host.setAttribute('foo:bar', ''); - expect(extractPropsFromElement(fixture.host)).to.eql({}); + expect(extractPropsFromElement(fixture.host)).toEqual({}); }); describe('error', () => { it('should throw if binding has no key', () => { const fixture = new ElementFixture(); fixture.host.setAttribute('bind:value', ''); - expect(() => extractPropsFromElement(fixture.host)).to.throw( + expect(() => extractPropsFromElement(fixture.host)).toThrow( `COMPONENT-ERROR(Q-401): 'bind:id' must have a property name. (Example: 'bind:key="propertyName"').` ); }); it('should throw if binding has no value', () => { const fixture = new ElementFixture(); fixture.host.setAttribute('bind:', '$key'); - expect(() => extractPropsFromElement(fixture.host)).to.throw( + expect(() => extractPropsFromElement(fixture.host)).toThrow( `COMPONENT-ERROR(Q-400): 'bind:' must have an key. (Example: 'bind:key="propertyName"').` ); }); diff --git a/src/core/util/base_uri.unit.ts b/src/core/util/base_uri.unit.ts index 9bc1104fcc7..28718fa34d3 100644 --- a/src/core/util/base_uri.unit.ts +++ b/src/core/util/base_uri.unit.ts @@ -6,17 +6,16 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { getBaseUri } from './base_uri.js'; +import { getBaseUri } from './base_uri'; describe('getBaseUri', () => { it('should get this file', () => { - expect(getBaseUri()).to.include('base_uri.unit.js'); + expect(getBaseUri()).toContain('base_uri.unit.js'); }); it('should getBaseUri equal import.meta.url', () => { - let baseURI = getBaseUri(); + const baseURI = getBaseUri(); // For some reason the sourcemap have extra util in the path. - baseURI = baseURI.replace('/util/util/', '/util/'); - expect(baseURI).to.equal(import.meta.url); + // baseURI = baseURI.replace('/util/util/', '/util/'); + expect(baseURI.replace('.js', '')).toEqual(__filename.replace('.ts', '')); }); }); diff --git a/src/core/util/case.unit.ts b/src/core/util/case.unit.ts index d26f048e4b2..ca934418845 100644 --- a/src/core/util/case.unit.ts +++ b/src/core/util/case.unit.ts @@ -6,21 +6,20 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { fromCamelToKebabCase, fromKebabToCamelCase } from './case.js'; +import { fromCamelToKebabCase, fromKebabToCamelCase } from './case'; describe('case', () => { describe('fromCamelToKebabCase', () => { it('should convert to kebab', () => { - expect(fromCamelToKebabCase('HelloWorld')).to.equal('hello-world'); - expect(fromCamelToKebabCase('a:b')).to.equal('a:b'); + expect(fromCamelToKebabCase('HelloWorld')).toEqual('hello-world'); + expect(fromCamelToKebabCase('a:b')).toEqual('a:b'); }); }); describe('fromKebabToCamelCase', () => { it('should convert to camel', () => { - expect(fromKebabToCamelCase('hello-world')).to.equal('HelloWorld'); - expect(fromKebabToCamelCase('-hello-world')).to.equal('HelloWorld'); + expect(fromKebabToCamelCase('hello-world')).toEqual('HelloWorld'); + expect(fromKebabToCamelCase('-hello-world')).toEqual('HelloWorld'); }); }); }); diff --git a/src/core/util/dirname.unit.ts b/src/core/util/dirname.unit.ts index 119dcfefb96..04adf86f6a7 100644 --- a/src/core/util/dirname.unit.ts +++ b/src/core/util/dirname.unit.ts @@ -6,15 +6,14 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { dirname } from './dirname.js'; +import { dirname } from './dirname'; describe('dirname', () => { it('should strip filename and keep ending slash', () => { - expect(dirname('dir/path/file.ext')).to.equal('dir/path/'); + expect(dirname('dir/path/file.ext')).toEqual('dir/path/'); }); it('should strip dirname and keep ending slash', () => { - expect(dirname('dir/path/')).to.equal('dir/'); + expect(dirname('dir/path/')).toEqual('dir/'); }); }); diff --git a/src/core/util/dom.unit.ts b/src/core/util/dom.unit.ts index a23e8e5621a..c66116660e0 100644 --- a/src/core/util/dom.unit.ts +++ b/src/core/util/dom.unit.ts @@ -6,12 +6,11 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { createGlobal, QwikGlobal } from '../testing/node_utils.js'; -import { isDomElementWithTagName } from './types.js'; +import { createGlobal, MockGlobal } from '@builder.io/qwik/testing'; +import { isDomElementWithTagName } from './types'; describe('dom', () => { - let global: QwikGlobal; + let global: MockGlobal; let div: HTMLElement; let span: HTMLElement; let text: Text; @@ -23,10 +22,9 @@ describe('dom', () => { }); it('isDomElementWithTagName', () => { - expect(isDomElementWithTagName(null, 'dIv')).to.equal(false); - expect(isDomElementWithTagName(span, 'dIv')).to.equal(false); - expect(isDomElementWithTagName(text, 'dIv')).to.equal(false); - - expect(isDomElementWithTagName(div, 'dIv')).to.equal(true); + expect(isDomElementWithTagName(null, 'dIv')).toEqual(false); + expect(isDomElementWithTagName(span, 'dIv')).toEqual(false); + expect(isDomElementWithTagName(text, 'dIv')).toEqual(false); + expect(isDomElementWithTagName(div, 'dIv')).toEqual(true); }); }); diff --git a/src/core/util/dom_attrs.unit.ts b/src/core/util/dom_attrs.unit.ts index b441aef65b0..d5307cc02c3 100644 --- a/src/core/util/dom_attrs.unit.ts +++ b/src/core/util/dom_attrs.unit.ts @@ -6,10 +6,9 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { QError } from '../error/error.js'; -import { ElementFixture } from '../testing/element_fixture.js'; -import { findAttribute } from './dom_attrs.js'; +import { QError } from '../error/error'; +import { ElementFixture } from '@builder.io/qwik/testing'; +import { findAttribute } from './dom_attrs'; describe('dom_attrs', () => { describe('findAttribute', () => { @@ -27,34 +26,32 @@ describe('dom_attrs', () => { value, }) ) - ).to.eql({ + ).toEqual({ element: fixture.parent, key: 'primary', value: 'primaryValue', }); }); - it('should find either attr', () => { - it('should find one attr', () => { - const fixture = new ElementFixture(); - fixture.parent.setAttribute('secondary', 'secondaryValue'); - expect( - findAttribute( - fixture.child, - QError.Core_noAttribute_atr1_element, - 'primary', - () => null, - 'secondary', - (element, key, value) => ({ - element, - key, - value, - }) - ) - ).to.eql({ - element: fixture.parent, - key: 'secondary', - value: 'secondaryValue', - }); + it('should find one attr', () => { + const fixture = new ElementFixture(); + fixture.parent.setAttribute('secondary', 'secondaryValue'); + expect( + findAttribute( + fixture.child, + QError.Core_noAttribute_atr1_element, + 'primary', + () => null, + 'secondary', + (element, key, value) => ({ + element, + key, + value, + }) + ) + ).toEqual({ + element: fixture.parent, + key: 'secondary', + value: 'secondaryValue', }); }); describe('error', () => { @@ -62,7 +59,7 @@ describe('dom_attrs', () => { const fixture = new ElementFixture(); expect(() => findAttribute(fixture.host, QError.Core_noAttribute_atr1_element, 'primary', () => null) - ).to.throw( + ).toThrow( `ERROR(Q-003): Could not find entity state 'primary' at '' or any of it's parents.` ); }); @@ -77,7 +74,7 @@ describe('dom_attrs', () => { 'secondary', () => null ) - ).to.throw( + ).toThrow( `ERROR(Q-004): Could not find entity state 'primary' ( or entity provider 'secondary') at '' or any of it's parents.` ); }); diff --git a/src/core/util/string.unit.ts b/src/core/util/string.unit.ts index 90a006f51a6..4ebba8f5210 100644 --- a/src/core/util/string.unit.ts +++ b/src/core/util/string.unit.ts @@ -6,17 +6,16 @@ * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ -import { expect } from 'chai'; -import { caseInsensitiveCompare } from './string.js'; +import { caseInsensitiveCompare } from './string'; describe('string', () => { it('should caseInsensitiveCompare', () => { - expect(caseInsensitiveCompare(null, null)).to.equal(false); - expect(caseInsensitiveCompare('a', null)).to.equal(false); - expect(caseInsensitiveCompare(null, 'b')).to.equal(false); - expect(caseInsensitiveCompare('a', 'bb')).to.equal(false); + expect(caseInsensitiveCompare(null, null)).toEqual(false); + expect(caseInsensitiveCompare('a', null)).toEqual(false); + expect(caseInsensitiveCompare(null, 'b')).toEqual(false); + expect(caseInsensitiveCompare('a', 'bb')).toEqual(false); - expect(caseInsensitiveCompare('a', 'a')).to.equal(true); - expect(caseInsensitiveCompare('aBc', 'AbC')).to.equal(true); + expect(caseInsensitiveCompare('a', 'a')).toEqual(true); + expect(caseInsensitiveCompare('aBc', 'AbC')).toEqual(true); }); }); diff --git a/src/core/util/test_component_fixture.tsx b/src/core/util/test_component_fixture.tsx new file mode 100644 index 00000000000..bbb60cd2250 --- /dev/null +++ b/src/core/util/test_component_fixture.tsx @@ -0,0 +1,71 @@ +import { assertDefined } from '../assert/assert'; +import { QRL } from '../import'; +import { toFileUrl } from '@builder.io/qwik/testing'; +import { h } from '@builder.io/qwik'; +import { Component } from '../component'; +import { Entity } from '../entity'; + +//////////////////////////////////////////////////////////// +// `GreeterComponent` definition useful for writing tests +//////////////////////////////////////////////////////////// +export interface GreeterProps { + salutation: string; + name: string; +} +export interface Greeter { + greeting: string; +} + +export class GreeterComponent extends Component { + static $templateQRL = QRL`${toFileUrl(__filename).replace(/\.tsx$/, '#greeterTemplate')}`; + + greeting: string = null!; + + async $init() { + this.greeting = this.$state.greeting; + } + + async $newState(state: GreeterProps) { + return { greeting: state.salutation + ' ' + state.name + '!' }; + } +} + +export function greeterTemplate(props: GreeterProps) { + return ( + + {props.salutation} {props.name}! + + ); +} + +//////////////////////////////////////////////////////////// +// `PersonEntity` definition useful for writing tests +//////////////////////////////////////////////////////////// + +export interface PersonProps { + first: string; + last: string; +} + +export interface Person { + first: string; + last: string; + age: number; +} + +export class PersonEntity extends Entity { + static $qrl = QRL`${toFileUrl(__filename).replace(/\.tsx$/, '#PersonEntity')}`; + static $type = 'Person'; + static $keyProps = [`last`, 'first']; + + async $newState(props: PersonProps): Promise { + const { first, last } = props; + assertDefined(first, 'first missing'); + assertDefined(last, 'last missing'); + return { + first, + last, + age: first.length + last.length, + }; + } +} diff --git a/src/core/util/test_config.ts b/src/core/util/test_config.ts new file mode 100644 index 00000000000..f2516a9c1fc --- /dev/null +++ b/src/core/util/test_config.ts @@ -0,0 +1,12 @@ +import { toFileUrl } from '@builder.io/qwik/testing'; + +export const TEST_CONFIG = { + baseURI: toFileUrl(__filename), + protocol: { + test: '../', + import: '../import/', + jsx: '../render/jsx/', + entity: '../entity/', + injection: '../injector/', + }, +};