Skip to content

Commit

Permalink
Switch to mocha with jsdom
Browse files Browse the repository at this point in the history
  • Loading branch information
pletcher committed May 11, 2016
1 parent d4edee0 commit c098f72
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 49 deletions.
1 change: 1 addition & 0 deletions .#beatles.js
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

# Created by https://www.gitignore.io/api/node

### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

.results.json
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@

## Instructions

Make sure you run the tests with `learn -b` to get the full output in the browser.
Make sure you run the tests with `learn`.

+ Create a function `theBeatlesPlay`, which accepts two parameters- an array of musicians and an array of instruments. The body of the function should create an empty array stored in a variable. The function should also contain a for loop which loops over the array of musicians. You'll want to be careful about what value you set your counter variable to store. (Hint: Think about what the first index of an array is). The first time through the loop, the body of the loop should create a string using the first index of the musicians array and the first index of the instruments array: `"John Lennon plays guitar"`. This string should be added to the empty array you created. The loop should make the same sentence for every member of the musicians array. The function should return the array of new strings.

+ Create a function `johnLennonFacts`. Inside the function, create an array which contains facts about John Lennon:

```js
facts = ["He was the last Beatle to learn to drive", "He was never a vegetarian", "He was a choir boy and boy scout", "He hated the sound of his own voice"];
const facts = [
"He was the last Beatle to learn to drive",
"He was never a vegetarian",
"He was a choir boy and boy scout",
"He hated the sound of his own voice"
];
```

The function should also create a second variable that stores an empty array. Use a while loop to loop over the facts array and add `"!!!"` to the end of every fact. The new string with the exclamation points should be added to the empty array.
Expand Down
40 changes: 39 additions & 1 deletion beatles.js
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
'use strict';
function theBeatlesPlay(musicians, instruments) {
const arr = []

for (let i = 0, l = musicians.length; i < l; i++) {
arr.push(`${musicians[i]} plays ${instruments[i]}`)
}

return arr
}

function johnLennonFacts() {
const facts = [
"He was the last Beatle to learn to drive",
"He was never a vegetarian",
"He was a choir boy and boy scout",
"He hated the sound of his own voice"
]

const shoutedFacts = []

let i = 0
while (i < facts.length) {
shoutedFacts.push(`${facts[i]}!!!`)
i++
}

return shoutedFacts
}

function iLoveTheBeatles(n) {
const arr = []

do {
arr.push('I love the Beatles!')
n++
} while (n < 15)

return arr
}
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "js-beatles-loops-lab",
"version": "0.1.0",
"description": "JavaScript for Beatles Fans",
"main": "beatles.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "mocha -R mocha-multi --reporter-options nyan=-,json=.results.json"
},
"repository": {
"type": "git",
"url": "git+https://github.com/learn-co-curriculum/js-beatles-loops-lab.git"
},
"keywords": [
"javascript",
"beatles",
"flatiron",
"loops"
],
"author": "@vicfriedman",
"license": "SEE LICENSE IN LICENSE.md",
"bugs": {
"url": "https://github.com/learn-co-curriculum/js-beatles-loops-lab/issues"
},
"homepage": "https://github.com/learn-co-curriculum/js-beatles-loops-lab#readme",
"devDependencies": {
"chai": "^3.5.0",
"jsdom": "^9.0.0",
"mocha": "^2.4.5",
"mocha-jsdom": "^1.1.0",
"mocha-multi": "^0.9.0"
}
}
5 changes: 0 additions & 5 deletions requires.yml

This file was deleted.

41 changes: 0 additions & 41 deletions spec/beatles_spec.js

This file was deleted.

35 changes: 35 additions & 0 deletions test/beatles-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*global beforeEach, describe, it */

const expect = require('chai').expect
const fs = require('fs')
const jsdom = require('mocha-jsdom')
const path = require('path')

describe('theBeatlesPlay', () => {
jsdom({
src: fs.readFileSync(path.resolve(__dirname, '..', 'beatles.js'), 'utf-8')
})

it("returns an array of strings containing what instruments each instrument plays", () => {
const musicians = ["John Lennon", "Paul McCartney", "George Harrison", "Ringo Starr"];
const instruments = ["Guitar", "Bass Guitar", "Lead Guitar", "Drums"];

expect(theBeatlesPlay(musicians, instruments)).to.eql(["John Lennon plays Guitar", "Paul McCartney plays Bass Guitar", "George Harrison plays Lead Guitar", "Ringo Starr plays Drums"]);
});

describe('johnLennonFacts', () => {
it("returns an array of strings with exclamation points", () => {
expect(johnLennonFacts()).to.eql(["He was the last Beatle to learn to drive!!!", "He was never a vegetarian!!!", "He was a choir boy and boy scout!!!", "He hated the sound of his own voice!!!"]);
});
});

describe('iLoveTheBeatles', () => {
it("returns an array of 'I love the Beatles!' 8 times when passed the parameter 7 ", () => {
expect(iLoveTheBeatles(7)).to.eql(["I love the Beatles!", "I love the Beatles!", "I love the Beatles!", "I love the Beatles!", "I love the Beatles!", "I love the Beatles!", "I love the Beatles!", "I love the Beatles!"]);
});

it("returns an array of 'I love the Beatles!' once when passed the parameter 17", () => {
expect(iLoveTheBeatles(17)).to.eql(["I love the Beatles!"]);
});
});
});

0 comments on commit c098f72

Please sign in to comment.