New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

testdouble

Package Overview
Dependencies
Maintainers
2
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

testdouble - npm Package Compare versions

Comparing version 3.15.0 to 3.16.0

lib/instance.js

8

CHANGELOG.md
# Change Log
## 3.15
* Add support for faking native ES modules with `td.replaceEsm()` [#445](https://github.com/testdouble/testdouble.js/pull/445)
## 3.14
* Type updates [#437](https://github.com/testdouble/testdouble.js/pull/437)
## 3.13.1

@@ -4,0 +12,0 @@

25

index.d.ts

@@ -139,2 +139,19 @@ //

//
// fake: instance objects
//
/**
* Construct an instance of a faked class.
*
* @export
* @template T
* @param {{ new (...args: any[]): T }} constructor
* @returns {DoubledObject<typeof T>}
*/
export function instance<T>(
constructor: Constructor<T>
): DoubledObject<T>;
//
// fake: functions

@@ -256,3 +273,3 @@ // ----------------------------------------------------------------------------

/**
* Swap out real dependenencies with fake one. Intercept calls to `require`
* Swap out real dependencies with fake one. Intercept calls to `require`
* that dependency module and ensure your subject is handed a fake instead.

@@ -267,3 +284,3 @@ *

/**
* Swap out real dependenencies with fake one. Intercept calls to `require`
* Swap out real dependencies with fake one. Intercept calls to `require`
* that dependency module and ensure your subject is handed a fake instead.

@@ -278,3 +295,3 @@ *

/**
* Swap out real dependenencies with fake one. Intercept calls to `import`
* Swap out real dependencies with fake one. Intercept calls to `import`
* that dependency module and ensure your subject is handed a fake instead.

@@ -292,3 +309,3 @@ *

/**
* Swap out real dependenencies with fake one. Reference to the property will
* Swap out real dependencies with fake one. Reference to the property will
* be replace it during your test.

@@ -295,0 +312,0 @@ *

@@ -6,2 +6,3 @@ "use strict";

const constructor_1 = require("./constructor");
const instance_1 = require("./instance");
const imitate_1 = require("./imitate");

@@ -23,2 +24,3 @@ const when_1 = require("./when");

constructor: constructor_1.default,
instance: instance_1.default,
imitate: imitate_1.default,

@@ -25,0 +27,0 @@ when: when_1.default,

2

lib/object.js

@@ -35,3 +35,3 @@ "use strict";

}, {});
var ensureFunctionIsNotPassed = () => log_1.default.error('td.object', 'Functions are not valid arguments to `td.object` (as of testdouble@2.0.0). Please use `td.function()` or `td.constructor()` instead for creating fake functions.');
var ensureFunctionIsNotPassed = () => log_1.default.error('td.object', 'Functions are not valid arguments to `td.object` (as of testdouble@2.0.0). Please use `td.function()`, `td.constructor()` or `td.instance()` instead for creating fake functions.');
var ensureOtherGarbageIsNotPassed = () => log_1.default.error('td.object', `\

@@ -38,0 +38,0 @@ To create a fake object with td.object(), pass it a plain object that contains

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = '3.15.0';
exports.default = '3.16.0';
{
"name": "testdouble",
"version": "3.15.0",
"version": "3.16.0",
"description": "A minimal test double library for TDD with JavaScript",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/testdouble/testdouble.js",

@@ -245,3 +245,3 @@ # testdouble.js (AKA td.js)

### `td.func()`, `td.object()`, `td.constructor()`, and `td.imitate()` to create test doubles
### `td.func()`, `td.object()`, `td.constructor()`, `td.instance()` and `td.imitate()` to create test doubles

@@ -336,2 +336,24 @@ `td.replace()`'s imitation and injection convenience is great when your

#### `td.instance()`
If your code depends on ES classes or functions, then the `td.instance()` function
will create a mock constructor and return a new instance of that mock constructor.
The following code snippets are functionally equiavalent:
```js
const fakeObject = td.instance(RealConstructor)
td.when(fakeObject.doStuff()).thenReturn('just did it')
fakeObject.doStuff() // returns "just did it"
```
```js
const FakeConstructor = td.constructor(RealConstructor)
const fakeObject = new FakeConstructor()
td.when(fakeObject.doStuff()).thenReturn('just did it')
fakeObject.doStuff() // returns "just did it"
```
#### `td.imitate()`

@@ -338,0 +360,0 @@

import tdFunction from './function'
import object from './object'
import constructor from './constructor'
import instance from './instance'
import imitate from './imitate'

@@ -21,2 +22,3 @@ import when from './when'

constructor,
instance,
imitate,

@@ -23,0 +25,0 @@ when,

@@ -35,3 +35,3 @@ import _ from './wrap/lodash'

var ensureFunctionIsNotPassed = () =>
log.error('td.object', 'Functions are not valid arguments to `td.object` (as of testdouble@2.0.0). Please use `td.function()` or `td.constructor()` instead for creating fake functions.')
log.error('td.object', 'Functions are not valid arguments to `td.object` (as of testdouble@2.0.0). Please use `td.function()`, `td.constructor()` or `td.instance()` instead for creating fake functions.')

@@ -38,0 +38,0 @@ var ensureOtherGarbageIsNotPassed = () =>

@@ -1,1 +0,1 @@

export default '3.15.0'
export default '3.16.0'

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc