File: test.js

package info (click to toggle)
node-execa 8.0.1%2Bdfsg1%2B~cs12.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,588 kB
  • sloc: javascript: 2,940; makefile: 11; sh: 1
file content (33 lines) | stat: -rw-r--r-- 777 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import test from 'ava';
import onetime from './index.js';

test('call function once', t => {
	let i = 0;
	const fixture = onetime(() => ++i);
	t.is(fixture(), 1);
	t.is(fixture(), 1);
	t.is(fixture(), 1);
});

test('option to throw is called more than once', t => {
	const fixture = onetime(() => {}, {throw: true});
	fixture();
	t.throws(fixture, {message: /Function .* can only be called once/});
});

test('`callCount` method', t => {
	const fixture = onetime(() => {});
	t.is(onetime.callCount(fixture), 0);
	fixture();
	fixture();
	fixture();
	t.is(onetime.callCount(fixture), 3);
});

test('`callCount` method - throw on non-onetime-wrapped functions', t => {
	const fixture = () => {};

	t.throws(() => {
		onetime.callCount(fixture);
	}, {message: /not wrapped/});
});