Sha256: 93765e5cb351c6be5448cd7ab7bc961a606beb6032251114117d678399e823fe

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

describe("toHaveBeenCalledWith", function() {
  it("passes when the actual was called with matching parameters", function() {
    var util = {
          contains: jasmine.createSpy('delegated-contains').and.callReturn(true)
        },
        matcher = j$.matchers.toHaveBeenCalledWith(util),
        calledSpy = j$.createSpy('called-spy'),
        result;

    calledSpy('a', 'b');
    result = matcher.compare(calledSpy, 'a', 'b');

    expect(result.pass).toBe(true);
  });

  it("fails when the actual was not called", function() {
    var util = {
          contains: jasmine.createSpy('delegated-contains').and.callReturn(false)
        },
        matcher = j$.matchers.toHaveBeenCalledWith(util),
        uncalledSpy = j$.createSpy('uncalled spy'),
        result;

    result = matcher.compare(uncalledSpy);
    expect(result.pass).toBe(false);
  });

  it("fails when the actual was called with different parameters", function() {
    var util = {
          contains: jasmine.createSpy('delegated-contains').and.callReturn(false)
        },
        matcher = j$.matchers.toHaveBeenCalledWith(util),
        calledSpy = j$.createSpy('called spy'),
        result;

    calledSpy('a');
    result = matcher.compare(calledSpy, 'a', 'b');

    expect(result.pass).toBe(false);
  });

  it("throws an exception when the actual is not a spy", function() {
    var matcher = j$.matchers.toHaveBeenCalledWith(),
        fn = function() {};

    expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function."));
  });

  it("has a custom message on failure", function() {
    var matcher = j$.matchers.toHaveBeenCalledWith(),
        spy = j$.createSpy('sample-spy'),
        messages = matcher.message(spy);

    expect(messages.affirmative).toEqual("Expected spy sample-spy to have been called.")
    expect(messages.negative).toEqual("Expected spy sample-spy not to have been called.")
  });
});

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jasmine-core-2.0.0.rc2 ./lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js