-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
228d484
commit 734bdaa
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
packages/@glimmer-workspace/integration-tests/test/keywords/if-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { defineComponent, jitSuite, RenderTest, test, tracked } from '../..'; | ||
|
||
class LogTest extends RenderTest { | ||
static suiteName = '{{log}} keyword'; | ||
|
||
originalLog?: () => void; | ||
logCalls: unknown[] = []; | ||
|
||
beforeEach() { | ||
/* eslint-disable no-console */ | ||
this.originalLog = console.log; | ||
console.log = (...args: unknown[]) => { | ||
this.logCalls.push(...args); | ||
/* eslint-enable no-console */ | ||
}; | ||
} | ||
|
||
afterEach() { | ||
/* eslint-disable no-console */ | ||
console.log = this.originalLog!; | ||
/* eslint-enable no-console */ | ||
} | ||
|
||
assertLog(values: unknown[]) { | ||
this.assertHTML(''); | ||
this.assert.strictEqual(this.logCalls.length, values.length); | ||
|
||
for (let i = 0, len = values.length; i < len; i++) { | ||
this.assert.strictEqual(this.logCalls[i], values[i]); | ||
} | ||
} | ||
|
||
@test | ||
'inline if can swap render components'() { | ||
class State { | ||
@tracked cond = true; | ||
flip = () => (this.cond = !this.cond); | ||
} | ||
|
||
let state = new State(); | ||
|
||
const Foo = defineComponent({}, 'Foo'); | ||
const ooF = defineComponent({}, 'ooF'); | ||
const Bar = defineComponent({ Foo, ooF, state }, '{{if state.cond Foo ooF}}'); | ||
|
||
this.renderComponent(Bar); | ||
|
||
this.assertHTML('Foo'); | ||
|
||
state.flip(); | ||
this.rerender(); | ||
this.assertHTML('ooF'); | ||
|
||
state.flip(); | ||
this.rerender(); | ||
this.assertHTML('Foo'); | ||
} | ||
} | ||
|
||
jitSuite(LogTest); |