Testing
No need to test your logic through the UI or using React with libraries like react-testing-library
or react-hook-testing-library
.
You can simply test your logic with Jest, pretty quickly and easily develop some features using test driven development (TDD)
// counter.test.ts
import { createCore } from 'cortex/setup/setup';
describe('counter', () => {
it('should be incremented', () => {
const core = createCore();
const service = core.getService('counter');
expect(service.state.count).toBe(0)
service.increment()
expect(service.state.count).toBe(1)
service.increment()
expect(service.state.count).toBe(2)
})
it('should be decremented', () => {
const core = createCore();
const service = core.getService('counter');
service.state.count = 5
service.decrement()
expect(service.state.count).toBe(4)
service.decrement()
expect(service.state.count).toBe(3)
})
it('should not be decremented at a lower value than 0', () => {
const core = createCore();
const service = core.getService('counter');
service.state.count = 1
service.decrement()
expect(service.state.count).toBe(0)
service.decrement()
expect(service.state.count).toBe(0)
})
})