Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #38 from hanshs/automated-testing
Browse files Browse the repository at this point in the history
setup Jest and React Testing Library closes #37
  • Loading branch information
normanpirk authored Nov 7, 2021
2 parents 31d54c3 + c6a8776 commit 3f19751
Show file tree
Hide file tree
Showing 9 changed files with 18,931 additions and 2,600 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/automated_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Automated Tests

on: [push, pull_request]

jobs:
run_automated_tests:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 15.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
- name: Install dependencies
run: npm install
- name: Run unit tests
run: npm test
3 changes: 3 additions & 0 deletions __mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// __mocks__/fileMock.js

(module.exports = "test-file-stub")
3 changes: 3 additions & 0 deletions __mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// __mocks__/styleMock.js

module.exports = {};
4 changes: 4 additions & 0 deletions __tests__/example.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

test('testing jest configuration', () => {
expect(true).toBe(true);
});
27 changes: 27 additions & 0 deletions __tests__/theorem.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Theorem from "../components/Theorem";
import { render } from '@testing-library/react'

const testTheorem = {
claim: {
statement: 'I am thorem statement',
successor: {
statement: 'I am detailed statement'
}
},
proof: [
{ claim: { statement: 'Step 1' } },
{
claim: { statement: 'Step 2' },
subProof: [
{ claim: { statement: 'Step 2 Subproof Step 1', successor: { statement: 'Step 2 Subproof Step 1 more detailed' } } },
{ claim: { statement: 'Step 2 Subproof Step 2' } }
]
},
{ claim: { statement: 'Step 3' } },
{ claim: { statement: 'Step 4' } }
]
}

it('renders a theorem', () => {
render(<Theorem theorem={testTheorem} />)
})
34 changes: 34 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// jest .config.js

module.exports = {
collectCoverageFrom: [
'**/*.{js,jsx,ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**',
],
moduleNameMapper: {
/* Handle CSS imports (with CSS modules)
https://jestjs.io/docs/webpack#mocking-css-modules */
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',

// Handle CSS imports (without CSS modules)
'^.+\\.(css|sass|scss)$': '<rootDir>/__mocks__/styleMock.js',

/* Handle image imports
https://jestjs.io/docs/webpack#handling-static-assets */
'^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$':
'<rootDir>/__mocks__/fileMock.js',
},
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'],
testEnvironment: 'jsdom',
transform: {
/* Use babel-jest to transpile tests with the next/babel preset
https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object */
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }],
},
transformIgnorePatterns: [
'/node_modules/',
'^.+\\.module\\.(css|sass|scss)$',
],
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
}
3 changes: 3 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// jest.setup.js

import '@testing-library/jest-dom/extend-expect'
Loading

1 comment on commit 3f19751

@vercel
Copy link

@vercel vercel bot commented on 3f19751 Nov 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.