Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 430, support ember-source 3.13 #460

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions addon-test-support/ember-mocha/setup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import {
setupContext,
teardownContext
} from '@ember/test-helpers';
import { assign, merge } from '@ember/polyfills';
import { resolve } from 'rsvp';

const _assign = assign || merge;

function chainHooks(hooks, context) {
return hooks.reduce((promise, fn) => promise.then(fn.bind(context)), resolve());
}
Expand All @@ -25,32 +22,40 @@ function setupPauseTest(context) {
}

export default function setupTest(options) {
let originalContext;
let beforeEachHooks = [];
let afterEachHooks = [];
let isInternalKey = () => false;

beforeEach(function() {
originalContext = _assign({}, this);


return setupContext(this, options)
.then(() => setupPauseTest(this))
.then(() => chainHooks(beforeEachHooks, this));
.then(() => chainHooks(beforeEachHooks, this))
.then(() => {
// use a closure to capture the state of `this`
// so we can reliably compare the difference later
let originalContext = Object.keys(this);
isInternalKey = key => originalContext.includes(key);
});
});

afterEach(function() {

let teardownUserKeysAndOwner = () => {
// compare what has been currently set
// on the test context with what was
// there from internal test setup
Object.keys(this).filter(key => !isInternalKey(key))
.forEach(key => this.set(key, null));

// we must forcibly remove owner
// and cannot clear it using `this.set`
delete this.owner;
};
return chainHooks(afterEachHooks, this)
.then(() => teardownContext(this))
.then(() => {
// delete any extraneous properties
for (let key in this) {
if (!(key in originalContext)) {
delete this[key];
}
}

// copy over the original values
_assign(this, originalContext);
});
.then(() => teardownUserKeysAndOwner());
});

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/setup-rendering-test-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ describe('setupRenderingTest', function() {
await render(hbs`{{pretty-color name=name}}`);
expect(this.element.textContent.trim()).to.equal('Pretty Color:');
});

it('renders a third time with', async function() {
let value = 'red';
this.set('name', value);
expect(this.get('name')).to.equal(value);
expect(this.name).to.equal(value);
await render(hbs`{{pretty-color name=name}}`);
expect(this.element.textContent.trim()).to.equal(`Pretty Color: ${value}`);
});

it('can set properties using dot notation that have been tracked in prior tests', async function() {
this.name = 'indigo';
await render(hbs`{{pretty-color name=name}}`);
expect(this.element.textContent.trim()).to.equal('Pretty Color: indigo');
});

});

describe('hooks API', function() {
Expand Down