expect-even-more-jest
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -0,1 +1,3 @@ | ||
/// <reference types="jest" /> | ||
import Mock = jest.Mock; | ||
import "expect-more-jest"; | ||
@@ -13,2 +15,5 @@ export declare function sleep(ms: number): Promise<void>; | ||
export declare function areEqual(left: any, right: any, debug?: boolean): boolean; | ||
export declare function isJasmineSpy(a: any): boolean; | ||
export declare function isJestMock(a: any): boolean; | ||
export declare function fetchArgs(subject: Mock | jasmine.Spy): any[]; | ||
declare global { | ||
@@ -15,0 +20,0 @@ namespace jest { |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringLike = exports.prettyPrint = exports.notFor = exports.runAssertionsAsync = exports.runAssertions = exports.assert = exports.areEqual = exports.sleep = void 0; | ||
exports.stringLike = exports.prettyPrint = exports.notFor = exports.runAssertionsAsync = exports.runAssertions = exports.assert = exports.fetchArgs = exports.isJestMock = exports.isJasmineSpy = exports.areEqual = exports.sleep = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
@@ -33,2 +33,30 @@ require("expect-more-jest"); | ||
exports.areEqual = areEqual; | ||
function isJasmineSpy(a) { | ||
return a && | ||
a.calls && | ||
typeof a.calls.all === "function"; | ||
} | ||
exports.isJasmineSpy = isJasmineSpy; | ||
function isJestMock(a) { | ||
return a && | ||
a.mock && | ||
Array.isArray(a.mock.calls); | ||
} | ||
exports.isJestMock = isJestMock; | ||
function fetchArgs(subject) { | ||
// jasmine spies come from doing `spyOn(thing, "method")` | ||
// jest mocks come from `jest.fn()` | ||
if (isJasmineSpy(subject)) { | ||
const spy = subject; | ||
return spy.calls.all().map(c => c.args); | ||
} | ||
else if (isJestMock(subject)) { | ||
const mock = subject; | ||
return mock.mock.calls; | ||
} | ||
else { | ||
throw new Error(`${subject} doesn't appear to be a jasmine spy or a jest mock?`); | ||
} | ||
} | ||
exports.fetchArgs = fetchArgs; | ||
function assert(expr, failMessage) { | ||
@@ -267,16 +295,3 @@ if (!expr) { | ||
expect(actual).toHaveBeenCalledWith(...args); | ||
let allArgs; | ||
// jasmine spies come from doing `spyOn(thing, "method")` | ||
// jest mocks come from `jest.fn()` | ||
if (isJasmineSpy(actual)) { | ||
const spy = actual; | ||
allArgs = spy.calls.all().map(c => c.args); | ||
} | ||
else if (isJestMock(actual)) { | ||
const mock = actual; | ||
allArgs = mock.mock.calls; | ||
} | ||
else { | ||
throw new Error("actual doesn't appear to be a spy or a mock?"); | ||
} | ||
const allArgs = fetchArgs(actual); | ||
const matching = allArgs.filter(a => { | ||
@@ -294,12 +309,2 @@ try { | ||
}); | ||
function isJasmineSpy(a) { | ||
return a && | ||
a.calls && | ||
typeof a.calls.all === "function"; | ||
} | ||
function isJestMock(a) { | ||
return a && | ||
a.mock && | ||
Array.isArray(a.mock.calls); | ||
} | ||
}, | ||
@@ -306,0 +311,0 @@ async toBeCompleted(actual) { |
{ | ||
"name": "expect-even-more-jest", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "expect-more-jest with even more stuff", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23190
497