Change set up to each of the formats
This goes against DRY principle, but it was recommended by Jasmine team to reduce coupling between tests.
This commit is contained in:
@@ -1,33 +1,40 @@
|
|||||||
describe('toHaveSpyInteractions', function() {
|
describe('toHaveSpyInteractions', function() {
|
||||||
let spyObj;
|
|
||||||
beforeEach(function() {
|
|
||||||
spyObj = jasmine.createSpyObj('NewClass', ['spyA', 'spyB']);
|
|
||||||
spyObj.otherMethod = function() {};
|
|
||||||
});
|
|
||||||
|
|
||||||
it('detects spy interactions', function() {
|
it('detects spy interactions', function() {
|
||||||
|
let spyObj = jasmine.createSpyObj('NewClass', ['spyA', 'spyB']);
|
||||||
|
|
||||||
spyObj.spyA();
|
spyObj.spyA();
|
||||||
|
|
||||||
expect(spyObj).toHaveSpyInteractions();
|
expect(spyObj).toHaveSpyInteractions();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('detects multiple spy interactions', function() {
|
it('detects multiple spy interactions', function() {
|
||||||
|
let spyObj = jasmine.createSpyObj('NewClass', ['spyA', 'spyB']);
|
||||||
|
|
||||||
spyObj.spyA();
|
spyObj.spyA();
|
||||||
spyObj.spyB();
|
spyObj.spyB();
|
||||||
spyObj.spyA();
|
spyObj.spyA();
|
||||||
|
|
||||||
expect(spyObj).toHaveSpyInteractions();
|
expect(spyObj).toHaveSpyInteractions();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('detects no spy interactions', function() {
|
it('detects no spy interactions', function() {
|
||||||
|
let spyObj = jasmine.createSpyObj('NewClass', ['spyA', 'spyB']);
|
||||||
|
|
||||||
expect(spyObj).not.toHaveSpyInteractions();
|
expect(spyObj).not.toHaveSpyInteractions();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ignores non-observed spy object interactions', function() {
|
it('ignores non-observed spy object interactions', function() {
|
||||||
|
let spyObj = jasmine.createSpyObj('NewClass', ['spyA', 'spyB']);
|
||||||
|
|
||||||
spyObj.otherMethod();
|
spyObj.otherMethod();
|
||||||
|
|
||||||
expect(spyObj).not.toHaveSpyInteractions();
|
expect(spyObj).not.toHaveSpyInteractions();
|
||||||
});
|
});
|
||||||
|
|
||||||
[true, 123, 'string'].forEach(function(testValue) {
|
[true, 123, 'string'].forEach(function(testValue) {
|
||||||
it(`throws error if a non-object (${testValue}) is passed`, function() {
|
it(`throws error if a non-object (${testValue}) is passed`, function() {
|
||||||
|
let spyObj = jasmine.createSpyObj('NewClass', ['spyA', 'spyB']);
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
expect(true).toHaveSpyInteractions();
|
expect(true).toHaveSpyInteractions();
|
||||||
}).toThrowError(Error, /Expected a spy object, but got/);
|
}).toThrowError(Error, /Expected a spy object, but got/);
|
||||||
@@ -36,6 +43,8 @@ describe('toHaveSpyInteractions', function() {
|
|||||||
|
|
||||||
[['argument'], [false, 0]].forEach(function(testValue) {
|
[['argument'], [false, 0]].forEach(function(testValue) {
|
||||||
it(`throws error if arguments (${testValue}) are passed`, function() {
|
it(`throws error if arguments (${testValue}) are passed`, function() {
|
||||||
|
let spyObj = jasmine.createSpyObj('NewClass', ['spyA', 'spyB']);
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
expect(spyObj).toHaveSpyInteractions(...testValue);
|
expect(spyObj).toHaveSpyInteractions(...testValue);
|
||||||
}).toThrowError(Error, /Does not take arguments/);
|
}).toThrowError(Error, /Does not take arguments/);
|
||||||
@@ -43,12 +52,12 @@ describe('toHaveSpyInteractions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('throws error if spy object has no spies', function() {
|
it('throws error if spy object has no spies', function() {
|
||||||
const newSpyObj = jasmine.createSpyObj('OtherClass', ['method']);
|
const spyObj = jasmine.createSpyObj('NewClass', ['method']);
|
||||||
// Removing spy since spy objects cannot be created without spies.
|
// Removing spy since spy objects cannot be created without spies.
|
||||||
newSpyObj.method = function() {};
|
spyObj.method = function() {};
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
expect(newSpyObj).toHaveSpyInteractions();
|
expect(spyObj).toHaveSpyInteractions();
|
||||||
}).toThrowError(
|
}).toThrowError(
|
||||||
Error,
|
Error,
|
||||||
/Expected a spy object with spies, but object has no spies/
|
/Expected a spy object with spies, but object has no spies/
|
||||||
|
|||||||
Reference in New Issue
Block a user