Skip to content

Instantly share code, notes, and snippets.

View phudekar's full-sized avatar

Pradip Hudekar phudekar

  • Sahaj Software
  • India
View GitHub Profile
@phudekar
phudekar / e2e.test.js
Created October 12, 2020 10:46
testing spa - e2e tests
it('should toggle flag of a block', () => {
cy.visit("/");
cy.get(".flag").should("not.be.visible");
const block = cy.get(".block").first();
block.rightclick();
cy.get(".flag").should("be.visible");
block.rightclick();
cy.get(".flag").should("not.be.visible");
})
@phudekar
phudekar / compone-integration.test.js
Created October 12, 2020 10:37
testing spa - component integration tests
it('should reveal block', () => {
const rows = 5;
const columns = 5;
const board = new Board(rows, columns);
const { container } = render(<BoardComponent board={board} />)
const block = container.querySelectorAll('.block')[0];
fireEvent.click(block);
expect(board.blocks[0][0].revealed).toBe(true);
})
@phudekar
phudekar / single-component.js
Created October 12, 2020 10:30
testig spa - single component tests
it('should call onRevealed after left click', () => {
const block = new Block(position);
const reveal = jest.fn();
const { getByTestId } = render(<BlockComponent block={block} onReveal={reveal} />);
const root = getByTestId(`block-${position.row}-${position.column}`);
fireEvent.click(root);
expect(reveal).toHaveBeenCalled();
})
@phudekar
phudekar / unit-test.js
Created October 12, 2020 10:21
testing spa - unit test
it('should explode if it has mine', () => {
const mine = true;
const block = new Block(new Position(1, 1), mine);
const { mineExploded } = block.reveal([]);
expect(mineExploded).toBeTruthy();
})
it('should not explode if it does not have mine', () => {
const block = new Block(new Position(1, 1));
const { mineExploded } = block.reveal([]);