#1015 - revert formatting and spacing
This commit is contained in:
@@ -1,102 +1,88 @@
|
|||||||
describe("toHaveBeenCalledTimes", function () {
|
describe("toHaveBeenCalledTimes", function() {
|
||||||
|
it("passes when the actual 0 matches the expected 0 ", function () {
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
|
calledSpy = jasmineUnderTest.createSpy('called-spy'),
|
||||||
|
result;
|
||||||
|
result = matcher.compare(calledSpy, 0);
|
||||||
|
expect(result.pass).toBeTruthy();
|
||||||
|
});
|
||||||
|
it("passes when the actual matches the expected", function() {
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
|
calledSpy = jasmineUnderTest.createSpy('called-spy'),
|
||||||
|
result;
|
||||||
|
calledSpy();
|
||||||
|
|
||||||
it("passes when the actual 0 matches the expected 0 ", function () {
|
result = matcher.compare(calledSpy, 1);
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
expect(result.pass).toBe(true);
|
||||||
calledSpy = jasmineUnderTest.createSpy('called-spy'),
|
});
|
||||||
result;
|
|
||||||
result = matcher.compare(calledSpy, 0);
|
|
||||||
expect(result.pass).toBeTruthy();
|
|
||||||
});
|
|
||||||
it("passes when the actual matches the expected", function () {
|
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
|
||||||
calledSpy = jasmineUnderTest.createSpy('called-spy'),
|
|
||||||
result;
|
|
||||||
calledSpy();
|
|
||||||
|
|
||||||
result = matcher.compare(calledSpy, 1);
|
it("fails when expected numbers is not supplied", function(){
|
||||||
expect(result.pass).toBeTruthy();
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
});
|
spy = jasmineUnderTest.createSpy('spy'),
|
||||||
|
result;
|
||||||
|
|
||||||
it("fails when expected number is not supplied", function () {
|
spy();
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
expect(function() {
|
||||||
spy = jasmineUnderTest.createSpy('spy'),
|
matcher.compare(spy);
|
||||||
result;
|
}).toThrowError('Expected times failed is required as an argument.');
|
||||||
|
});
|
||||||
|
|
||||||
spy();
|
it("fails when the actual was called less than the expected", function() {
|
||||||
expect(function () {
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
matcher.compare(spy);
|
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
|
||||||
}).toThrowError('The expected times failed is a required argument and must be a number.');
|
result;
|
||||||
});
|
|
||||||
|
|
||||||
it("fails when expected number is a string", function () {
|
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
|
||||||
spy = jasmineUnderTest.createSpy('spy'),
|
|
||||||
result;
|
|
||||||
|
|
||||||
spy();
|
result = matcher.compare(uncalledSpy, 2);
|
||||||
expect(function () {
|
expect(result.pass).toBe(false);
|
||||||
matcher.compare(spy, "1");
|
});
|
||||||
}).toThrowError('The expected times failed is a required argument and must be a number.');
|
|
||||||
});
|
|
||||||
|
|
||||||
it("fails when the actual was called less than the expected", function () {
|
it("fails when the actual was called more than expected", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
|
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(uncalledSpy, 2);
|
uncalledSpy();
|
||||||
expect(result.pass).toBeFalsy();
|
uncalledSpy();
|
||||||
});
|
|
||||||
|
|
||||||
it("fails when the actual was called more than expected", function () {
|
result = matcher.compare(uncalledSpy, 1);
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
expect(result.pass).toBe(false);
|
||||||
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
|
});
|
||||||
result;
|
|
||||||
|
|
||||||
uncalledSpy();
|
it("throws an exception when the actual is not a spy", function() {
|
||||||
uncalledSpy();
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
|
fn = function() {};
|
||||||
|
|
||||||
result = matcher.compare(uncalledSpy, 1);
|
expect(function() {
|
||||||
expect(result.pass).toBeFalsy();
|
matcher.compare(fn);
|
||||||
});
|
}).toThrowError("Expected a spy, but got Function.");
|
||||||
|
});
|
||||||
|
|
||||||
it("throws an exception when the actual is not a spy", function () {
|
it("has a custom message on failure that tells it was called only once", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
fn = function () { };
|
spy = jasmineUnderTest.createSpy('sample-spy'),
|
||||||
|
result;
|
||||||
|
spy();
|
||||||
|
spy();
|
||||||
|
spy();
|
||||||
|
spy();
|
||||||
|
|
||||||
expect(function () {
|
result = matcher.compare(spy, 1);
|
||||||
matcher.compare(fn);
|
expect(result.message).toEqual('Expected spy sample-spy to have been called once. It was called ' + 4 + ' times.');
|
||||||
}).toThrowError("Expected a spy, but got Function.");
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it("has a custom message on failure that tells it was called only once", function () {
|
it("has a custom message on failure that tells how many times it was called", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
spy = jasmineUnderTest.createSpy('sample-spy'),
|
spy = jasmineUnderTest.createSpy('sample-spy'),
|
||||||
result;
|
result;
|
||||||
spy();
|
spy();
|
||||||
spy();
|
spy();
|
||||||
spy();
|
spy();
|
||||||
spy();
|
spy();
|
||||||
|
|
||||||
result = matcher.compare(spy, 1);
|
result = matcher.compare(spy, 2);
|
||||||
|
expect(result.message).toEqual('Expected spy sample-spy to have been called 2 times. It was called ' + 4 + ' times.');
|
||||||
expect(result.message).toEqual('Expected spy sample-spy to have been called once. It was called ' + 4 + ' times.');
|
});
|
||||||
});
|
/*
|
||||||
|
|
||||||
it("has a custom message on failure that tells how many times it was called", function () {
|
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
|
||||||
spy = jasmineUnderTest.createSpy('sample-spy'),
|
|
||||||
result;
|
|
||||||
spy();
|
|
||||||
spy();
|
|
||||||
spy();
|
|
||||||
spy();
|
|
||||||
|
|
||||||
result = matcher.compare(spy, 2);
|
|
||||||
|
|
||||||
expect(result.message).toEqual('Expected spy sample-spy to have been called 2 times. It was called ' + 4 + ' times.');
|
|
||||||
});
|
|
||||||
/*
|
|
||||||
it("should work when chained to expect", function(){
|
it("should work when chained to expect", function(){
|
||||||
// test for the way we'll use it in real code
|
// test for the way we'll use it in real code
|
||||||
var foo = {
|
var foo = {
|
||||||
|
|||||||
Reference in New Issue
Block a user