From d2efb1454825d10a30ddb88a4e7fcf2183c012cd Mon Sep 17 00:00:00 2001 From: Chris Garrett Date: Fri, 17 Apr 2020 14:32:00 -0700 Subject: [PATCH 1/2] [Refactor] refactors tests to use tracked utility --- .../@glimmer/core/test/interactive/fn-test.ts | 15 ++++++------ .../core/test/interactive/helper-test.ts | 23 ++++++------------- .../core/test/interactive/modifier-test.ts | 12 ++++++---- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/packages/@glimmer/core/test/interactive/fn-test.ts b/packages/@glimmer/core/test/interactive/fn-test.ts index 9e6f37ad6..822bbdec2 100644 --- a/packages/@glimmer/core/test/interactive/fn-test.ts +++ b/packages/@glimmer/core/test/interactive/fn-test.ts @@ -1,6 +1,5 @@ -import { module, test, render, settled } from '../utils'; +import { module, test, render, settled, tracked as trackedObj} from '../utils'; import Component from '@glimmer/component'; -import { tracked } from '@glimmer/tracking'; import { fn } from '@glimmer/helper'; import { on, action } from '@glimmer/modifier'; @@ -13,10 +12,10 @@ module('[@glimmer/core] interactive - {{fn}}', () => { let helloWorldComponent: HelloWorld; let passedMsg1, passedMsg2, passedEvent: MouseEvent | undefined; + const args = trackedObj({ name: 'world' }) + class HelloWorld extends Component { - @tracked - name = 'world'; - + constructor(owner: unknown, args: {}) { super(owner, args); helloWorldComponent = this; @@ -34,12 +33,12 @@ module('[@glimmer/core] interactive - {{fn}}', () => { setComponentTemplate( createTemplate( { on, fn }, - '' + '' ), HelloWorld ); - const output = await render(HelloWorld); + const output = await render(HelloWorld, { args }); assert.strictEqual(output, ''); @@ -52,7 +51,7 @@ module('[@glimmer/core] interactive - {{fn}}', () => { assert.ok(passedEvent instanceof MouseEvent); passedEvent = undefined; - helloWorldComponent!.name = 'cruel world'; + args.name = 'cruel world'; await settled(); diff --git a/packages/@glimmer/core/test/interactive/helper-test.ts b/packages/@glimmer/core/test/interactive/helper-test.ts index e594b55b8..4fc92f3c8 100644 --- a/packages/@glimmer/core/test/interactive/helper-test.ts +++ b/packages/@glimmer/core/test/interactive/helper-test.ts @@ -1,4 +1,4 @@ -import { module, test, render, settled } from '../utils'; +import { module, test, render, settled, tracked as trackedObj } from '../utils'; import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; @@ -19,28 +19,19 @@ module('[@glimmer/core] interactive - helper', () => { return `helper ${greeting} ${name}`; } - let component: MyComponent; + const args = trackedObj({ name: 'Rob' }); - class MyComponent extends Component { - constructor(owner: unknown, args: {}) { - super(owner, args); - component = this; - } - - @tracked name = 'Rob'; - } - - setComponentTemplate( - createTemplate({ myHelper }, '

{{myHelper this.name "Hello"}}

'), - MyComponent + const MyComponent = setComponentTemplate( + createTemplate({ myHelper }, '

{{myHelper @name "Hello"}}

'), + templateOnlyComponent() ); - let html = await render(MyComponent); + let html = await render(MyComponent, { args }); assert.strictEqual(html, '

helper Hello Rob

', 'the template was rendered'); assert.equal(count, 1, 'helper rendered once'); - component!.name = 'Tom'; + args.name = 'Tom'; html = await settled(); diff --git a/packages/@glimmer/core/test/interactive/modifier-test.ts b/packages/@glimmer/core/test/interactive/modifier-test.ts index 4148c5a79..0af3a550d 100644 --- a/packages/@glimmer/core/test/interactive/modifier-test.ts +++ b/packages/@glimmer/core/test/interactive/modifier-test.ts @@ -53,25 +53,27 @@ setModifierManager((owner) => new CustomModifierManager(owner), CustomModifier); module('Modifier Tests', () => { test('Supports the on modifier', async (assert) => { + + const args = tracked({ count: 0 }); + class MyComponent extends Component { - @tracked count = 0; @action incrementCounter(): void { - this.count++; + args.count++; } } setComponentTemplate( createTemplate( { on }, - `` + `` ), MyComponent ); assert.strictEqual( - await render(MyComponent), + await render(MyComponent, { args }), ``, 'the component was rendered' ); @@ -305,7 +307,7 @@ module('Modifier Tests', () => { templateOnlyComponent() ); - const html = await render(Component); + const html = await render(Component,); assert.equal(html, `

hello world

`, 'rendered correctly'); assert.deepEqual(hooks, ['insert'], 'correct hooks called on initial render'); From b713600d1d657704b95e25d430e15b2d1829f602 Mon Sep 17 00:00:00 2001 From: Rahil Vora Date: Fri, 17 Apr 2020 17:17:53 -0700 Subject: [PATCH 2/2] [Refactor] Adds more test files to use tracked utility --- packages/@glimmer/core/test/interactive/fn-test.ts | 6 ++---- packages/@glimmer/core/test/interactive/modifier-test.ts | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/@glimmer/core/test/interactive/fn-test.ts b/packages/@glimmer/core/test/interactive/fn-test.ts index 822bbdec2..949b427c7 100644 --- a/packages/@glimmer/core/test/interactive/fn-test.ts +++ b/packages/@glimmer/core/test/interactive/fn-test.ts @@ -1,4 +1,4 @@ -import { module, test, render, settled, tracked as trackedObj} from '../utils'; +import { module, test, render, settled, tracked } from '../utils'; import Component from '@glimmer/component'; import { fn } from '@glimmer/helper'; import { on, action } from '@glimmer/modifier'; @@ -12,10 +12,8 @@ module('[@glimmer/core] interactive - {{fn}}', () => { let helloWorldComponent: HelloWorld; let passedMsg1, passedMsg2, passedEvent: MouseEvent | undefined; - const args = trackedObj({ name: 'world' }) - + const args = tracked({ name: 'world' }); class HelloWorld extends Component { - constructor(owner: unknown, args: {}) { super(owner, args); helloWorldComponent = this; diff --git a/packages/@glimmer/core/test/interactive/modifier-test.ts b/packages/@glimmer/core/test/interactive/modifier-test.ts index 0af3a550d..36f9d7baa 100644 --- a/packages/@glimmer/core/test/interactive/modifier-test.ts +++ b/packages/@glimmer/core/test/interactive/modifier-test.ts @@ -53,11 +53,9 @@ setModifierManager((owner) => new CustomModifierManager(owner), CustomModifier); module('Modifier Tests', () => { test('Supports the on modifier', async (assert) => { - const args = tracked({ count: 0 }); - - class MyComponent extends Component { + class MyComponent extends Component { @action incrementCounter(): void { args.count++; @@ -307,7 +305,7 @@ module('Modifier Tests', () => { templateOnlyComponent() ); - const html = await render(Component,); + const html = await render(Component); assert.equal(html, `

hello world

`, 'rendered correctly'); assert.deepEqual(hooks, ['insert'], 'correct hooks called on initial render');