
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
unit-test-sentinel
Advanced tools
Provides a sentinel object that can contain and return arbitrary unique properties for unit tests.
Provides unique objects for unit tests in JavaScript. Inspired by the sentinel object in Python.
It's useful for creating a value that is passed into a function call, but you don't want to keep track of this value in a local variable. Instead, you can ask the sentinel to give you a unique named property that will persist through your test.
npm install --save-dev unit-test-sentinel
Import the module sentinel and then create a sentinel object for each test. This example uses Mocha and calls the sentinel object Ń„ (which is U+0444).
import sentinel from 'unit-test-sentinel'
// We'll test this function.
const logAndReturn = (input) => {
console.log(input);
return input;
};
describe('logAndReturn', () => {
let Ń„;
beforeEach(() => {
// Create a sentinel object, which can contain arbirary properties.
Ń„ = sentinel.create();
})
it('returns its input', () => {
// Pass in a custom input, as a named property.
const result = logAndReturn(Ń„.customInput);
// Expect that the output is the exact same object that was passed in.
expect(result).to.equal(Ń„.customInput);
})
});
This example require()s the sentinel module, uses assert for testing, and calls the sentinel object s. It also uses the random method, calling its object r.
const sentinel = require('unit-test-sentinel');
const s = sentinel.create();
const r = sentinel.random();
const first = s.hello; // => ¦ф.hello¦
const second = s.hello; // => ¦ф.hello¦
assert(first === second); // âś“
const r1 = s.randomized; // e.g. => randomized-WfQ8S;0{|+)t
const r2 = s.randomized; // => randomized-WfQ8S;0{|+)t
assert(r1 === r2); // âś“
FAQs
Provides a sentinel object that can contain and return arbitrary unique properties for unit tests.
We found that unit-test-sentinel demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.