![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
chai-assert-change
Advanced tools
An assertion for chai.js to test the side-effects of a function.
npm install --save-dev chai-assert-change
You do need chai
to be installed.
function assertChange({
// The function that applies the side-effect.
//
// If this yields a Promise, we'll run the queries only once it resolves.
// We'll also propagate it back for you so that you can feed it to mocha
// or whatever else.
fn: function(): Any | Promise.<Any>,
// A function that returns the value we're inspecting. That is, the expected
// side-effect of the function.
of: function(value: Any): Any,
// A custom message to append to the assertion error to help you
// trace the assertion.
?it: String,
// --- QUERIES ---
// You can use only one of these for each side-effect you're testing.
// [1] [by]
//
// Test a change in a numerical value, like "X changes by 2" or
// "X changes by 0" as in it does not change.
?by: Number,
// [2] [from, to]
//
// Test non-numerical values for inequality; arrays, objects, or numbers
// too when a delta doesn't make sense.
//
// It is implemented using:
//
// chai.assert.deepEqual(a, b)
//
// To use this you need to fill in both "from" and "to".
?from: Any,
?to: Any,
// [3] [custom]
//
// A custom test; you are passed the values before and after applying
// the side-effect function and it's up to you to do the assertions.
?using: function(initialValue: Any, nextValue: Any): void
}): Any | Promise.<Any>
To test more than one side-effect you can define the in
property as an array
of the tests. So the fn
property remains at the root but the rest of the
properties go inside the in
entries.
Examples are shown in the next section.
import assertChange from 'chai-assert-change'
let x = 0
assertChange({
fn: () => { x += 1 },
of: () => x,
by: 1
})
let x = 0
let y = 0
assertChange({
fn: () => { x += 1 },
in: [
{
it: 'increments X',
of: () => x,
by: 1
},
{
it: 'does not touch Y',
of: () => y,
by: 0
}
]
})
Notice how we used it
to label the tests. These will be used in the assertion
message if it fails to hold.
The following example shows how the assertion will run the tests only after a promise resolves which is useful in async scenarios.
it('navigates', function() {
return assertChange({
fn: () => router.navigate('/b'),
of: () => location.pathname,
from: '/a',
to: '/b'
})
})
The promise is yielded back to you (with the value it resolved with) so that you can throw it back to your testing framework.
You can implement the using
hook to perform any kind of test instead of
inequality. Personally I'd recommend against this because it's more difficult
to reason about but sometimes it's necessary when, for example, dealing with
deeply nested structures.
assertChange({
fn: () => ...,
of: () => ...,
using: (a, b) => {
assert.notInclude(a, { foo: '1' })
assert.include(b, { foo: '1' })
}
})
MIT
FAQs
an assertion against a change to a value
We found that chai-assert-change demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.