Skip to content

Commit

Permalink
Merge pull request splendo#8 from corrado4eyes/corrado/tests
Browse files Browse the repository at this point in the history
Corrado/tests
  • Loading branch information
corrado4eyes authored Dec 3, 2019
2 parents abb1211 + 117656e commit 10a43a7
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 18 deletions.
22 changes: 22 additions & 0 deletions hearthstone/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import App from '../src/App';
import {shallow, ShallowWrapper} from 'enzyme'
import { dummyCardArray } from './__mocks__/mockObjects';
import Card from '../src/model/card';


describe('App', () => {
const cards: Card[] = dummyCardArray
it('renders n elements in an array', () => {
const component: ShallowWrapper = shallow(<App/>);
component.setState({cards: cards})
const divs: ShallowWrapper = component.find('.card');
expect(divs).toHaveLength(cards.length);
});

it('Snapshot testing', () => {
const component: ShallowWrapper = shallow(<App/>);
component.setState({cards: cards})
expect(component).toMatchSnapshot();
});
});
23 changes: 23 additions & 0 deletions hearthstone/__tests__/__mocks__/mockObjects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Card from "../../src/model/card";

export const dummyCard: Card = {
artist: "Corrado Quattrocchi",
cardId: "what a dummy card!",
cardSet: "Dummy",
collectible: true,
cost: 9999,
faction: "Splendo",
flavor: "Meat",
howToGet: "Ask Frits",
howToGetGold: "Feeds and Walk Frits for 2 years every day (excluded the holidays)",
img: "http://media.services.zam.com/v1/media/byName/hs/cards/enus/DS1_183.png",
imgGold: "http://media.services.zam.com/v1/media/byName/hs/cards/enus/animated/DS1_183_premium.gif",
locale: "enUS",
name: "corrado4eyes",
playerClass: "Human",
rarity: "Super Rare",
text: "A dummy Italian boy",
type: "Developer"
}

export const dummyCardArray = [dummyCard]
12 changes: 12 additions & 0 deletions hearthstone/__tests__/__snapshots__/App.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`App Snapshot testing 1`] = `
<Fragment>
<div
className="card"
key="what a dummy card!"
>
corrado4eyes
</div>
</Fragment>
`;
22 changes: 22 additions & 0 deletions hearthstone/__tests__/app.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import App from '../src/App';
import {shallow, ShallowWrapper} from 'enzyme'
import { dummyCardArray } from './__mocks__/mockObjects';
import Card from '../src/model/card';


describe('App', () => {
const cards: Card[] = dummyCardArray
it('renders n elements in an array', () => {
const component: ShallowWrapper = shallow(<App/>);
component.setState({cards: cards})
const divs: ShallowWrapper = component.find('.card');
expect(divs).toHaveLength(cards.length);
});

it('Snapshot testing', () => {
const component: ShallowWrapper = shallow(<App/>);
component.setState({cards: cards})
expect(component).toMatchSnapshot();
});
});
1 change: 1 addition & 0 deletions hearthstone/__tests__/config/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test-file-stub';
5 changes: 5 additions & 0 deletions hearthstone/__tests__/config/setupEnzyme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "reflect-metadata";
import Enzyme from "enzyme";
import Adapter from "enzyme-adapter-react-16";

Enzyme.configure({ adapter: new Adapter() });
1 change: 1 addition & 0 deletions hearthstone/__tests__/config/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
37 changes: 35 additions & 2 deletions hearthstone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,57 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/jest": "24.0.23",
"@types/node": "12.12.14",
"@types/react": "16.9.13",
"@types/react-dom": "16.9.4",
"awesome-typescript-loader": "^5.2.1",
"bootstrap": "^4.4.1",
"enzyme-to-json": "^3.4.3",
"inversify-react": "^0.4.3",
"jest": "^24.9.0",
"node-sass": "^4.13.0",
"react": "^16.12.0",
"react-bootstrap": "^1.0.0-beta.16",
"react-dom": "^16.12.0",
"react-scripts": "3.2.0",
"source-map-loader": "^0.2.4",
"ts-jest": "^24.2.0",
"ts-loader": "^6.2.1",
"typescript": "3.7.2",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"
},
"jest": {
"setupFilesAfterEnv": [
"<rootDir>/__tests__/config/setupEnzyme.js"
],
"testPathIgnorePatterns": [
"<rootDir>/__tests__/config/",
"<rootDir>/__tests__/__mocks__/"
],
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"preset": "ts-jest",
"transform": {
"^.+\\.js$": "ts-jest",
"\\.(ts|tsx)$": "ts-jest"
},
"moduleNameMapper": {
"\\.(css|scss|png|jpg|jpeg)$": "<rootDir>/__tests__/config/styleMock.js"
},
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx"
]
},
"scripts": {
"start": "webpack-dev-server --inline --content-base ./public",
"build": "webpack",
"test": "react-scripts test",
"test": "jest",
"eject": "react-scripts eject"
},
"eslintConfig": {
Expand All @@ -44,6 +72,11 @@
]
},
"devDependencies": {
"@types/enzyme": "^3.10.3",
"@types/jest": "^24.0.23",
"@types/mocha": "^5.2.7",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.15.1",
"html-webpack-plugin": "^3.2.0",
"inversify": "^5.0.1",
"inversify-inject-decorators": "^3.1.0",
Expand Down
9 changes: 0 additions & 9 deletions hearthstone/src/App.test.tsx

This file was deleted.

15 changes: 9 additions & 6 deletions hearthstone/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import container from '../config/inversify';

const serviceFactory = new ServiceFactory(container);


interface State {
cards: any[]
}
Expand All @@ -33,11 +32,15 @@ constructor(props: Props){
render(){
return (
<>
{this.state.cards.forEach((el: Card) => {
<div key={el.cardId}>
{el.name}
</div>
})}
{
this.state.cards.map((el: Card) => {
return (
<div key={el.cardId} className='card'>
{el.name}
</div>
)
})
}
</>
);
}
Expand Down
4 changes: 3 additions & 1 deletion hearthstone/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
"outDir": "dist/",
"noImplicitAny": true,
"experimentalDecorators": true,
"types": ["reflect-metadata", "jest", "mocha"]
},
"include": [
"./src/**/*",
"./__tests__/**/*"
],
"exclude": [
"./node_modules"
"./node_modules",
]
}

0 comments on commit 10a43a7

Please sign in to comment.