Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('test plugin shouldExecute', () => {
const context = new Context();
expect(applyOrReturn([context], deduplicate({ shouldExecute: false }).shouldExecute)).toBeFalsy();
expect(applyOrReturn([context], deduplicate({ shouldExecute: true }).shouldExecute)).toBeTruthy();
context.setState({ request: { deduplicateCache: false, url: '' } });
expect(applyOrReturn([context], deduplicate({ shouldExecute: true }).shouldExecute)).toBeFalsy();
context.setState({ request: { deduplicateCache: true, url: '' } });
expect(applyOrReturn([context], deduplicate({ shouldExecute: true }).shouldExecute)).toBeTruthy();
});
it('test shouldExecute', () => {
let shouldExecute = batch({ makeGroupedRequest }).shouldExecute;
expect(applyOrReturn([context], shouldExecute)).toBeFalsy();
shouldExecute = batch({ makeGroupedRequest }).shouldExecute;
expect(applyOrReturn([context], shouldExecute)).toBeFalsy();
context.setState({
request: {
batchKey: '123',
},
});
expect(applyOrReturn([context], shouldExecute)).toBeTruthy();
});
it('test shouldExecute', () => {
let shouldExecute = batch({ makeGroupedRequest }).shouldExecute;
expect(applyOrReturn([context], shouldExecute)).toBeFalsy();
shouldExecute = batch({ makeGroupedRequest }).shouldExecute;
expect(applyOrReturn([context], shouldExecute)).toBeFalsy();
context.setState({
request: {
batchKey: '123',
},
});
expect(applyOrReturn([context], shouldExecute)).toBeTruthy();
});
setState(stateOrFunc: Partial) {
const newState = applyOrReturn([this.state], stateOrFunc);
if (newState) {
this.state = {
...this.state,
...newState,
};
}
}