From f1cde2c4fd6a939e944e82621908c26814a4b88b Mon Sep 17 00:00:00 2001 From: Pete Cook Date: Mon, 14 Sep 2015 18:53:26 +0100 Subject: [PATCH] Add basic unit tests for static canPlay method --- README.md | 8 ++++++++ package.json | 3 +++ test/canPlay.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 test/canPlay.js diff --git a/README.md b/README.md index 15b3223c..daf1ec03 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/package.json b/package.json index 5cc59497..f26c0b12 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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", diff --git a/test/canPlay.js b/test/canPlay.js new file mode 100644 index 00000000..5295066b --- /dev/null +++ b/test/canPlay.js @@ -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 + }) +})