Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('calls the two handlers with the arguments provided', () => {
const spy1 = sinon.spy();
const spy2 = sinon.spy();
const merged = serialize(spy1, spy2);
// not call handlers in merging phase
expect(spy1).to.have.callCount(0);
expect(spy2).to.have.callCount(0);
merged(...ARGS);
// call handlers when calling merged function
expect(spy1).to.have.callCount(1);
expect(spy1).to.have.calledWithExactly(...ARGS);
expect(spy2).to.have.callCount(1);
expect(spy2).to.have.calledWithExactly(...ARGS);
});
describe.assuming(inBrowser(), 'only in browser')('react-decor-class', () => {
describe.assuming(inProduction(), 'only in production mode')('react contract regression tests', () => {
it('in production mode', () => {
// This test either passes or is ignored. It's here as a log artifact, to know whether other tests run in production mode
expect(process.env.NODE_ENV).to.eql('production');
});
});
const clientRenderer = new ClientRenderer();
afterEach(() => clientRenderer.cleanup());
function fooHook<p>>(_props: object, args: ElementArgs</p><p>) {
args.newProps['data-foo'] = 'foo';
return args;
}
function barHook</p><p>>(_props: object, args: ElementArgs</p><p>) {
args.newProps['data-bar'] = 'bar';
return args;
}
const fooDecorator = reactDecor.onEachElement(fooHook);
const barDecorator = reactDecor.onEachElement(barHook);
</p>
it("should work with custom symbols", () => {
const wrapper3 = reactDecor.makeFeature([hook]);
const symbol = {};
featuresApi.markFeatureWith(wrapper3, symbol);
const anotherWrappedComp = wrapper3(Comp);
expect(reactDecor.isDecorated(anotherWrappedComp, symbol), 'isDecorated by known symbol').to.equal(true);
expect(reactDecor.isDecorated(anotherWrappedComp, {}), 'isDecorated by unknown symbol').to.equal(false);
});
it("reflects decoration well", () => {
expect(classDecor.isDecorated(Foo), 'Foo').to.equal(false);
expect(classDecor.isDecorated(Bar), 'Bar').to.equal(true);
expect(classDecor.isDecorated(Biz), 'Biz').to.equal(true);
expect(classDecor.isDecorated(Baz), 'Baz').to.equal(true);
});
it(runId, () => {
resetAll(SPIES);
const obj = objProvider();
const result = obj.myMethod(ORIGIN_ARGUMENT);
expect(SPIES.firstBefore).to.have.callCount(1).and.calledWith(sinon.match.same(obj), [ORIGIN_ARGUMENT]);
expect(SPIES.lastBefore).to.have.callCount(1).and.calledWith(sinon.match.same(obj), [ORIGIN_ARGUMENT + 1]);
expect(SPIES.superClassFunction).to.have.callCount(0);
expect(SPIES.childFunction).to.have.callCount(1).and.calledWith(sinon.match.same(obj), ORIGIN_ARGUMENT + 2);
expect(SPIES.firstAfter).to.have.callCount(1).and.calledWith(sinon.match.same(obj), ORIGIN_RESULT);
expect(SPIES.lastAfter).to.have.callCount(1).and.calledWith(sinon.match.same(obj), ORIGIN_RESULT + 1);
expect(result).to.equal(ORIGIN_RESULT + 2);
});
}
it("should return true for a wrapped component", () => {
expect(reactDecor.isDecorated(WrappedComp)).to.equal(true);
});
beforeEach("replace console.warn with spy", () => {
console.warn = sinon.spy();
});
it('should call all appropriate handlers', () => {
const onMouseDown = sinon.spy();
const onMouseMove = sinon.spy();
const onMouseUp = sinon.spy();
clientRenderer.render(
);
windowStub.simulate('mousedown');
windowStub.simulate('mousemove');
windowStub.simulate('mouseup');
expect(onMouseDown).to.have.been.calledBefore(onMouseMove);
expect(onMouseMove).to.have.been.calledBefore(onMouseUp);
});
it('should call new handler but not the old one', () => {
const originalListener = sinon.spy();
const newListener = sinon.spy();
const fixture = clientRenderer.render(
).result as Fixture;
fixture.setState({listener: newListener});
windowStub.simulate('click');
expect(originalListener).not.to.have.been.called;
expect(newListener).to.have.been.calledOnce;
});
it('called on unmount', () => {
const spy = sinon.spy();
const {container} = clientRenderer.render(<div>);
clientRenderer.render(<div></div>, container);
expect(spy).to.have.callCount(0);
clientRenderer.render(<div>, container);
expect(spy).to.have.callCount(1);
});
});</div></div>