Last active
November 1, 2016 12:53
-
-
Save Carlsson87/15702ed5bc8ca83dd50a4e1da70e4c0a to your computer and use it in GitHub Desktop.
Components and such
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
export default React.createClass({ | |
/* | |
* För att testa logiken i denna metoden behöver vi | |
* en instans av denna komponenten, annars är "this" inte | |
* bundet till något och varken "props" eller "state" är tillgängliga. | |
*/ | |
doAllTheThings() { | |
return this.props.foo + this.state.bar; | |
}, | |
render() { | |
return ( | |
<div> | |
{ this.doAllTheThings() } | |
</div> | |
); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { expect } from 'chai'; | |
import { shallow } from 'enzyme'; | |
import Component from './now.js'; | |
describe('A Component', () => { | |
it('does all the things', () => { | |
const wrapper = shallow(<Component foo={ 2 }/>); | |
expect(wrapper.text()).to.equal("3"); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
/* | |
* Att testa funktionaliteten i denna funktionen är tämligen enkelt eftersom | |
* den inte är bunden till något. Den tar input och returnerar output. Den kan med | |
* fördel befinna sig i denna filen så länge den tjänar denna komponenten, skulle den | |
* senare visa sig vara användbar på andra ställen kan den antingen placeras på ett lämpligt | |
* ställe ELLER helt enkelt importeras från denna filen. | |
*/ | |
export function doAllTheThings(foo, bar) { | |
return foo + bar; | |
} | |
export default React.createClass({ | |
getInitialState() { | |
return { | |
bar: 1 | |
}; | |
}, | |
render() { | |
return ( | |
<div> | |
{ doAllTheThings(this.props.foo, this.state.bar) } | |
</div> | |
); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { expect } from 'chai'; | |
import { doAllTheThings } from './then.js'; | |
describe('A Component', () => { | |
it('does all the things', () => { | |
expect(doAllTheThings(1, 2)).to.equal(3); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment