Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@fast-check/ava
Advanced tools
@fast-check/ava
Bring the power of property based testing framework fast-check
into AVA.
@fast-check/ava
simplifies the integration of fast-check
into AVA testing framework.
Install @fast-check/ava
:
npm install --save-dev @fast-check/ava
In order to work properly, @fast-check/ava
requires ava
to be installed.
import { testProp, fc } from '@fast-check/ava';
// for all a, b, c strings
// b is a substring of a + b + c
testProp('should detect the substring', [fc.string(), fc.string(), fc.string()], (t, a, b, c) => {
t.true((a + b + c).includes(b));
});
The property is passed AVA's t
argument as its first parameter, and the value of each arbitrary for the current test case for the rest of the parameters.
@fast-check/ava
supports all of AVA's assertions and like AVA, it supports synchronous and asynchronous functions, including promises, observables, and callbacks. See AVA's documentation for more information.
⚠️ WARNING: When relying on @fast-check/ava
, returning true
or false
in your predicates is not taken into account. The library wants assertions or plans to be defined as ava
itself does. Nonetheless you can still use primitives such as fc.pre
to cut runs at the middle if some invariants are unmeet: the started plan (if any) will just be ignored.
fast-check
ParameterstestProp
accepts an optional fc.Parameters
for forwarding custom parameters to fast-check
(more).
import { testProp, fc } from '@fast-check/ava';
testProp(
'should detect the substring',
[fc.string(), fc.string(), fc.string()],
(t, a, b, c) => {
t.true((a + b + c).includes(b));
},
{ numRuns: 10 }, // Example of parameters
);
@fast-check/ava
also comes with .only
, .serial
.skip
, and .failing
modifiers from AVA.
import { testProp, fc } from '@fast-check/ava';
testProp(
'should replay the test for the seed 4242',
[fc.nat(), fc.nat()],
(t, a, b) => {
t.is(a + b, b + a);
},
{ seed: 4242 },
);
testProp.skip('should be skipped', [fc.fullUnicodeString()], (t, text) => {
t.is([...text].length, text.length);
});
before
/after
Hooks@fast-check/ava
exposes AVA's before
/after
hooks:
import { testProp, fc } from '@fast-check/ava';
testProp.before((t) => {
connectToDatabase();
});
testProp();
// ... omitted for brevity
testProp.after((t) => {
closeDatabaseConnection();
});
@fast-check/ava
mirror's AVA's procedure for customizing the test execution context:
import { fc, testProp as anyTestProp, PropertyTestInterface } from '@fast-check/ava';
type TestContext = {
state: string;
};
const testProp = anyTestProp as PropertyTestInterface<TestContext>;
testProp('should reach terminal state', [fc.string()], (t, received) => {
// here t is typed as ExecutionContext<TestContext>
console.log(t.context.state); // logs 'uninitialized'
// ... omitted for brevity
});
@fast-check/ava | AVA | fast-check |
---|---|---|
^2.0.0 | >=4.0.0 | ^3.0.0 |
^1.0.0 | >=4.0.0 | ^3.0.0 |
FAQs
Property based testing for AVA based on fast-check
We found that @fast-check/ava demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.