forked from rmurphey/js-assessment
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
node_modules/ |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
{ | |||
"people" : [ | |||
{ "name" : "Matt" }, | |||
{ "name" : "Rebecca" }, | |||
{ "name" : "Paul" }, | |||
{ "name" : "Alex" }, | |||
{ "name" : "Adam" } | |||
] | |||
} |
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
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
define([ 'use!underscore' ], function(_) { | |||
describe("arrays", function() { | |||
var a, b, fn; | |||
|
|||
beforeEach(function() { | |||
a = [ 1, 2, 3, 4 ]; | |||
b = { | |||
foo : 'bar', | |||
baz : 'bim' | |||
}; | |||
|
|||
fn = function() { }; | |||
}); | |||
|
|||
it("should be possible to determine the location of an item in an array", function() { | |||
// define a function for fn so that the following will pass | |||
expect(fn(a, 3)).to.be(2); | |||
}); | |||
|
|||
it("should be possible to add the values of an array", function() { | |||
// define a function for fn so that the following will pass | |||
expect(fn(a)).to.be(10); | |||
}); | |||
|
|||
it("should be possible to remove an item from an array", function() { | |||
// define a function for fn so that the following will pass | |||
var result = fn(a); | |||
expect(result).to.have.length(3); | |||
expect(result.join(' ')).to.be('1 3 4'); | |||
}); | |||
|
|||
it("should be possible to add an item to the end of an array", function() { | |||
// define a function for fn so that the following will pass | |||
var result = fn(a, 10); | |||
expect(result).to.have.length(5); | |||
expect(result[result.length - 1]).to.be(10); | |||
}); | |||
|
|||
it("should be possible to create an array from two arrays", function() { | |||
// define a function for fn so that the following will pass | |||
var c = [ 'a', 'b', 'c' ], | |||
result = fn(a, c); | |||
|
|||
expect(result).to.have.length(7); | |||
expect(result.join(' ')).to.be('1 2 3 4 a b c'); | |||
}); | |||
|
|||
it("should be possible to add an item anywhere in an array", function() { | |||
// define a function for fn so that the following will pass | |||
var result = fn(a, 'z', 2); | |||
|
|||
expect(result).to.have.length(5); | |||
expect(result.join(' ')).to.be('1 2 z 3 4'); | |||
}); | |||
}); | |||
}); |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,42 @@ | |||
define([ 'jquery', 'use!underscore' ], function($, _) { | |||
describe("async behavior", function() { | |||
var promise, fn = function() { }; | |||
|
|||
beforeEach(function() { | |||
|
|||
}); | |||
|
|||
it("should return a promise that resolves true", function(done) { | |||
var flag = false; | |||
|
|||
fn = function() { | |||
// write a function that makes the test pass | |||
}; | |||
|
|||
fn().then(function(result) { | |||
flag = result; | |||
expect(flag).to.be(true); | |||
done(); | |||
}); | |||
}); | |||
|
|||
it("should receive and manipulate data from the server", function(done) { | |||
var peopleArray, | |||
url = '/data/testdata.json', | |||
|
|||
tests = function() { | |||
expect(peopleArray).to.have.length(5); | |||
expect(peopleArray.join(' ')).to.be('Adam Alex Matt Paul Rebecca'); | |||
done(); | |||
}; | |||
|
|||
// replace the call to the tests function below with code that calls the | |||
// tests function once the data has been a) retrieved from the server and | |||
// b) manipulated so the tests will pass. | |||
|
|||
tests(); | |||
}); | |||
|
|||
}); | |||
|
|||
}); |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
define([ 'use!underscore' ], function(_) { | |||
describe("objects and context", function() { | |||
var a, b, fn = function() {}; | |||
|
|||
beforeEach(function() { | |||
a = { | |||
name : 'Matt', | |||
greeting : 'Hello', | |||
sayIt : function(preamble, punctuation) { | |||
return (preamble || '') + | |||
this.name + ', ' + | |||
this.greeting + | |||
(punctuation || '!'); | |||
} | |||
}; | |||
|
|||
b = { | |||
name : 'Rebecca', | |||
greeting : 'Yo' | |||
}; | |||
}); | |||
|
|||
it("should be able to alter the context in which a function runs", function() { | |||
fn = function() { }; | |||
expect(fn()).to.be('Yo, Rebecca!'); | |||
}); | |||
|
|||
it("should be able to pass in arguments stored in an array", function() { | |||
fn = function() { }; | |||
expect(fn()).to.be('Why Hello, Matt!!!'); | |||
}); | |||
}); | |||
}); |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,57 @@ | |||
define([ 'use!backbone', 'use!underscore', 'jquery' ], function(Backbone, _, $) { | |||
describe("a Backbone view", function() { | |||
var tpl, model, view; | |||
|
|||
beforeEach(function() { | |||
tpl = '<div id="my-view"><%= greeting %></div>'; | |||
model = new Backbone.Model({ | |||
greeting : 'Hello, world' | |||
}); | |||
|
|||
if (view && view.remove) { | |||
view.remove(); | |||
} | |||
}); | |||
|
|||
it("should render a view from a template", function() { | |||
var MyView = Backbone.View.extend({ | |||
template : tpl, | |||
render : function() { | |||
// write code here to make the tests below pass | |||
} | |||
}); | |||
|
|||
view = new MyView({ | |||
model : model | |||
}).render(); | |||
|
|||
expect(document.getElementById('my-view')).to.be.ok(); | |||
expect(document.getElementById('my-view').innerHTML).to.contain('Hello, world'); | |||
}); | |||
|
|||
it("should update the view when the model changes", function() { | |||
var MyView = Backbone.View.extend({ | |||
// fill in the code required in the initialize and render methods | |||
// to make the tests below pass | |||
initialize : function() { | |||
|
|||
}, | |||
template : tpl, | |||
render : function() { | |||
|
|||
} | |||
}); | |||
|
|||
view = new MyView({ | |||
model : model | |||
}).render(); | |||
|
|||
model.set('greeting', 'Goodbye, world'); | |||
|
|||
expect(document.getElementById('my-view').innerHTML).to.contain('Goodbye, world'); | |||
expect(document.getElementById('my-view').innerHTML).not.to.contain('Hello, world'); | |||
}); | |||
|
|||
}); | |||
|
|||
}); |
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