SHARE
TWEET

Untitled

a guest Sep 18th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ember-sinon-qunit (New)
  2.  
  3. // test-helper.js
  4. import { setApplication } from '@ember/test-helpers';
  5. import { start } from 'ember-qunit';
  6. import Application from '../app';
  7. import config from '../config/environment';
  8. import setupSinon from 'ember-sinon-qunit';
  9.  
  10. setApplication(Application.create(config.APP));
  11.  
  12. setupSinon();
  13.  
  14. start();
  15.  
  16. // foo-test.js
  17. import { module, test } from 'ember-qunit';
  18. import sinon from 'sinon';
  19.  
  20. module('Foo Test', function (hooks) {
  21.   hooks.beforeEach(function () {
  22.     // setup 'this.foo'
  23.     this.barSpy = sinon.spy(this.foo, 'bar');
  24.   });
  25. });
  26.  
  27. test('bar was called', function (assert) {
  28.   this.foo.bar();
  29.  
  30.   assert.ok(this.barSpy.calledOnce, 'bar was called');
  31. });
  32.  
  33. /**************************/
  34.  
  35. // ember-sinon-qunit (Old)
  36.  
  37. // foo-test.js
  38. import { module } from 'ember-qunit';
  39. import test from 'ember-sinon-qunit/test-support/test;
  40.  
  41. module('Foo Test', function (hooks) {
  42.   hooks.beforeEach(function () {
  43.     // setup 'this.foo'
  44.     this.barSpy = this.spy(this.foo, 'bar');
  45.   });
  46. });
  47.  
  48. test('bar was called', function (assert) {
  49.   this.foo.bar();
  50.  
  51.   assert.ok(this.barSpy.calledOnce, 'bar was called');
  52. });
  53.  
  54. /**************************/
  55.  
  56. // ember-sinon-sandbox
  57.  
  58. // foo-test.js
  59. import { module, test } from 'ember-qunit';
  60. import { setupSinonSandbox } from 'ember-sinon-sandbox/test-support';
  61.  
  62. module('Foo Test', function (hooks) {
  63.   setupSinonSandbox(hooks);
  64.  
  65.   hooks.beforeEach(function () {
  66.     // setup 'this.foo'
  67.     this.barSpy = this.sandbox.spy(this.foo, 'bar');
  68.   });
  69. });
  70.  
  71. test('bar was called', function (assert) {
  72.   this.foo.bar();
  73.  
  74.   assert.ok(this.barSpy.calledOnce, 'bar was called');
  75. });
  76.  
  77. /**************************/
  78.  
  79. // ember-sinon-sinoff
  80.  
  81. // foo-test.js
  82. import { module, test } from 'ember-qunit';
  83. import { setupSinonSinoff } from 'ember-sinon-sinoff/test-support';
  84.  
  85. module('Foo Test', function (hooks) {
  86.   setupSinonSinoff(hooks);
  87.  
  88.   hooks.beforeEach(function () {
  89.     // setup 'this.foo'
  90.     this.barSpy = this.sandbox.spy(this.foo, 'bar');
  91.   });
  92. });
  93.  
  94. test('bar was called', function (assert) {
  95.   this.foo.bar();
  96.  
  97.   assert.ok(this.barSpy.calledOnce, 'bar was called');
  98. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top