Socket
Socket
Sign inDemoInstall

expect

Package Overview
Dependencies
18
Maintainers
1
Versions
236
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.7.0 to 1.8.0

39

modules/__tests__/spy-test.js

@@ -22,9 +22,42 @@ var expect = require('../index');

var video = {
play: function () {},
pause: function () {},
rewind: function () {}
play: function () {}
};
var spy;
beforeEach(function () {
spy = expect.spyOn(video, 'play');
video.play('some', 'args');
});
it('tracks the number of calls', function () {
expect(spy.calls.length).toEqual(1);
});
it('tracks the context that was used', function () {
expect(spy.calls[0].context).toBe(video);
});
it('tracks the arguments that were used', function () {
expect(spy.calls[0].arguments).toEqual([ 'some', 'args' ]);
});
it('was called', function () {
expect(spy).toHaveBeenCalled();
});
it('was called with the correct args', function () {
expect(spy).toHaveBeenCalledWith('some', 'args');
});
it('can be restored', function () {
expect(video.play).toEqual(spy);
spy.restore();
expect(video.play).toNotEqual(spy);
});
});
describe('An undefined property that was spied on using spyOn', function () {
var video = {};
var spy;
beforeEach(function () {

@@ -31,0 +64,0 @@ spy = expect.spyOn(video, 'play');

16

modules/index.js

@@ -213,3 +213,8 @@ var assert = require('assert');

function noop() {}
function createSpy(fn) {
if (fn == null)
fn = noop;
expect(fn).toBeA(Function);

@@ -269,12 +274,9 @@

expect(original).toBeA(
Function,
formatString('%s does not have a method named "%s"', inspect(object), methodName)
);
if (original == null || !original.__isSpy) {
var spy = createSpy(original);
if (!original.__isSpy) {
var spy = createSpy(original);
spy.restore = function () {
spy.restore = spy.destroy = function () {
object[methodName] = original;
};
object[methodName] = spy;

@@ -281,0 +283,0 @@ }

{
"name": "expect",
"version": "1.7.0",
"version": "1.8.0",
"description": "Write better assertions",

@@ -5,0 +5,0 @@ "main": "modules/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc