Skip to content

Commit

Permalink
Add basic unit tests for static canPlay method
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Sep 14, 2015
1 parent 3c4c5fa commit f1cde2c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ This project uses [standard](https://github.com/feross/standard) code style.
npm run lint
```

### Testing

This project uses [mocha](https://github.com/mochajs/mocha) with [chai](https://github.com/chaijs/chai) assertions for unit testing.

```bash
npm run test
```

### Thanks

* Big thanks to [gaearon](https://github.com/gaearon) for his [react-hot-boilerplate](https://github.com/gaearon/react-hot-boilerplate), which this repo is roughly based on.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"start": "node server.js",
"lint": "standard",
"test": "mocha test --compilers js:babel/register",
"build": "babel src/ -d lib/",
"prepublish": "npm run build"
},
Expand Down Expand Up @@ -37,8 +38,10 @@
"babel-core": "^5.4.7",
"babel-eslint": "^4.0.10",
"babel-loader": "^5.1.2",
"chai": "^3.2.0",
"exports-loader": "^0.6.2",
"imports-loader": "^0.6.4",
"mocha": "^2.2.5",
"react": ">=0.13.0",
"react-hot-loader": "^1.2.7",
"standard": "^5.1.0",
Expand Down
45 changes: 45 additions & 0 deletions test/canPlay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { describe, it } from 'mocha'
import { expect } from 'chai'

import SoundCloud from '../src/players/SoundCloud'
import YouTube from '../src/players/YouTube'
import Vimeo from '../src/players/Vimeo'

describe('YouTube', () => {
it('knows what it can play', () => {
expect(YouTube.canPlay('https://www.youtube.com/watch?v=12345678901')).to.be.true
expect(YouTube.canPlay('http://www.youtube.com/watch?v=12345678901')).to.be.true
expect(YouTube.canPlay('https://youtube.com/watch?v=12345678901')).to.be.true
expect(YouTube.canPlay('http://youtube.com/watch?v=12345678901')).to.be.true
expect(YouTube.canPlay('http://youtu.be/12345678901')).to.be.true
})

it('knows what it can\'t play', () => {
expect(YouTube.canPlay('http://soundcloud.com/artist-name/title-name')).to.be.false
expect(YouTube.canPlay('http://vimeo.com/1234')).to.be.false
})
})

describe('SoundCloud', () => {
it('knows what it can play', () => {
expect(SoundCloud.canPlay('http://soundcloud.com/artist-name/title-name')).to.be.true
expect(SoundCloud.canPlay('http://snd.sc/artist-name/title-name')).to.be.true
})

it('knows what it can\'t play', () => {
expect(SoundCloud.canPlay('http://soundcloud.com/artist-only')).to.be.false
expect(SoundCloud.canPlay('https://www.youtube.com/watch?v=12345678901')).to.be.false
expect(SoundCloud.canPlay('http://vimeo.com/1234')).to.be.false
})
})

describe('Vimeo', () => {
it('knows what it can play', () => {
expect(Vimeo.canPlay('http://vimeo.com/1234')).to.be.true
})

it('knows what it can\'t play', () => {
expect(Vimeo.canPlay('http://soundcloud.com/artist-name/title-name')).to.be.false
expect(Vimeo.canPlay('https://www.youtube.com/watch?v=1234')).to.be.false
})
})

0 comments on commit f1cde2c

Please sign in to comment.