In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways. A computer programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the dynamic behavior. of a human in vehicle impacts.
test('renders without crashing', () => { const div = document.createElement('div'); ReactDOM.render(<Calculator />, div); });
// test optCalculator describe('optCalculator works normally', () => { test('+ get right results', () => { expect(optCalculator['+'](1, 2)).toBe(3); }); test('- get right results', () => { expect(optCalculator['-'](1, 2)).toBe(-1); }); });
// test formatNumer describe('formatNumber() works normally',() => { test('localize big num with ,',() => { expect(formatNumber(1234)).toBe('1,234'); expect(formatNumber(12345)).toBe('12,345'); }); test('with 6 fraction digits',() => { expect(formatNumber(1.01234567)).toBe('1.012346'); }); });