Created
September 6, 2019 21:57
-
-
Save elwayman02/0693c6f30579c9889d8b4b270866c928 to your computer and use it in GitHub Desktop.
Ember Sinon Cleanup Examples
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
// ember-sinon-qunit (New) | |
// test-helper.js | |
import { setApplication } from '@ember/test-helpers'; | |
import { start } from 'ember-qunit'; | |
import Application from '../app'; | |
import config from '../config/environment'; | |
import setupSinon from 'ember-sinon-qunit'; | |
setApplication(Application.create(config.APP)); | |
setupSinon(); | |
start(); | |
// foo-test.js | |
import { module, test } from 'ember-qunit'; | |
import sinon from 'sinon'; | |
module('Foo Test', function (hooks) { | |
hooks.beforeEach(function () { | |
// setup 'this.foo' | |
this.barSpy = sinon.spy(this.foo, 'bar'); | |
}); | |
}); | |
test('bar was called', function (assert) { | |
this.foo.bar(); | |
assert.ok(this.barSpy.calledOnce, 'bar was called'); | |
}); | |
/**************************/ | |
// ember-sinon-qunit (Old) | |
// foo-test.js | |
import { module } from 'ember-qunit'; | |
import test from 'ember-sinon-qunit/test-support/test; | |
module('Foo Test', function (hooks) { | |
hooks.beforeEach(function () { | |
// setup 'this.foo' | |
this.barSpy = this.spy(this.foo, 'bar'); | |
}); | |
}); | |
test('bar was called', function (assert) { | |
this.foo.bar(); | |
assert.ok(this.barSpy.calledOnce, 'bar was called'); | |
}); | |
/**************************/ | |
// ember-sinon-sandbox | |
// foo-test.js | |
import { module, test } from 'ember-qunit'; | |
import { setupSinonSandbox } from 'ember-sinon-sandbox/test-support'; | |
module('Foo Test', function (hooks) { | |
setupSinonSandbox(hooks); | |
hooks.beforeEach(function () { | |
// setup 'this.foo' | |
this.barSpy = this.sandbox.spy(this.foo, 'bar'); | |
}); | |
}); | |
test('bar was called', function (assert) { | |
this.foo.bar(); | |
assert.ok(this.barSpy.calledOnce, 'bar was called'); | |
}); | |
/**************************/ | |
// ember-sinon-sinoff | |
// foo-test.js | |
import { module, test } from 'ember-qunit'; | |
import { setupSinonSinoff } from 'ember-sinon-sinoff/test-support'; | |
module('Foo Test', function (hooks) { | |
setupSinonSinoff(hooks); | |
hooks.beforeEach(function () { | |
// setup 'this.foo' | |
this.barSpy = this.sandbox.spy(this.foo, 'bar'); | |
}); | |
}); | |
test('bar was called', function (assert) { | |
this.foo.bar(); | |
assert.ok(this.barSpy.calledOnce, 'bar was called'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment