From 6478343ac4113acabcad9a86f69fe85a55a12e5e Mon Sep 17 00:00:00 2001 From: Vildan Softic Date: Sun, 14 Jan 2018 13:33:09 +0100 Subject: [PATCH] feat(update): update bindings helper adds a helper function to flush the microtaskqueue so that testing binding changes becomes easier --- src/aurelia-testing.ts | 1 + src/update-bindings.ts | 9 +++++++++ test/doc-samples.spec.ts | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/update-bindings.ts diff --git a/src/aurelia-testing.ts b/src/aurelia-testing.ts index 70836a9..cb51417 100644 --- a/src/aurelia-testing.ts +++ b/src/aurelia-testing.ts @@ -3,6 +3,7 @@ export * from './compile-spy'; export * from './view-spy'; export * from './component-tester'; export * from './wait'; +export * from './update-bindings'; export function configure(config: FrameworkConfiguration) { config.globalResources([ diff --git a/src/update-bindings.ts b/src/update-bindings.ts new file mode 100644 index 0000000..9da5d63 --- /dev/null +++ b/src/update-bindings.ts @@ -0,0 +1,9 @@ +import { Container, TaskQueue } from 'aurelia-framework'; + +export function updateBindings() { + const tq: TaskQueue = Container.instance.get(TaskQueue); + + if (tq) { + tq.flushMicroTaskQueue(); + } +} diff --git a/test/doc-samples.spec.ts b/test/doc-samples.spec.ts index 2c376da..eba3534 100644 --- a/test/doc-samples.spec.ts +++ b/test/doc-samples.spec.ts @@ -1,5 +1,6 @@ import { StageComponent, ComponentTester } from '../src/component-tester'; import { bootstrap } from 'aurelia-bootstrapper'; +import { updateBindings } from '../src/update-bindings'; describe('SampleCustomComponent', () => { let component: ComponentTester; @@ -24,6 +25,24 @@ describe('SampleCustomComponent', () => { }); }); + it('should render new first name after update using helper', done => { + component.create(bootstrap) + .then(() => { + const nameElement = document.querySelector('.firstName') as Element; + expect(nameElement.innerHTML).toBe('Bob'); + + component.viewModel.firstName = 'TheBuilder'; + updateBindings(); + + expect(nameElement.innerHTML).toBe('TheBuilder'); + done(); + }) + .catch(error => { + fail(error); + done(); + }); + }); + afterEach(() => { component.dispose(); });