Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

more example tests

TJ Holowaychuk8bf17607dd42
diff --git a/example/Array.js b/example/Array.js
index 67ed6183..18105cf7 100644
--- a/example/Array.js
+++ b/example/Array.js
@@ -1,7 +1,7 @@
describe('Array', function(){
describe('.push()', function(){
- it('should add the values', function(){
+ it('should append a value', function(){
var arr = [];
arr.push('foo');
arr.push('bar');
@@ -27,12 +27,47 @@ describe('Array', function(){
})
})
+ describe('.unshift()', function(){
+ it('should prepend a value', function(){
+ var arr = [1,2,3];
+ arr.unshift('foo');
+ expect(arr[0]).to.equal('foo');
+ expect(arr[1]).to.equal(1);
+ })
+
+ it('should return the length', function(){
+ var arr = [];
+ var n = arr.unshift('foo');
+ expect(n).to.equal(1);
+ var n = arr.unshift('bar');
+ expect(n).to.equal(2);
+ })
+
+ describe('with many arguments', function(){
+ it('should add the values', function(){
+ var arr = [];
+ arr.unshift('foo', 'bar');
+ expect(arr[0]).to.equal('foo');
+ expect(arr[1]).to.equal('bar');
+ })
+ })
+ })
+
+ describe('.pop()', function(){
+ it('should remove and return the last value', function(){
+ var arr = [1,2,3];
+ expect(arr.pop()).to.equal(3);
+ expect(arr.pop()).to.equal(2);
+ expect(arr).to.have.length(1);
+ })
+ })
+
describe('.shift()', function(){
it('should remove and return the first value', function(){
var arr = [1,2,3];
expect(arr.shift()).to.equal(1);
expect(arr.shift()).to.equal(2);
- expect(arr.length).to.equal(1);
+ expect(arr).to.have.length(1);
})
})
})
\ No newline at end of file
diff --git a/example/String.js b/example/String.js
deleted file mode 100644
index 66f5741a..00000000
--- a/example/String.js
+++ /dev/null
@@ -1,15 +0,0 @@
-
-describe('String', function(){
- describe('.trim()', function(){
- it('should remove leading and trailing whitespace', function(){
- expect(' foo '.trim()).to.equal('foo');
- })
- })
-
- describe('.replace(substr, str)', function(){
- it('should replace the first occurrence of substr', function(){
- var str = 'foobar'.replace('foo', 'bar');
- expect(str).to.equal('barbar');
- })
- })
-})
\ No newline at end of file
diff --git a/example/tests.html b/example/tests.html
index 72a0da60..c7d4bb24 100644
--- a/example/tests.html
+++ b/example/tests.html
@@ -11,7 +11,6 @@
<script>mocha.setup('bdd')</script>
<script>expect = chai.expect</script>
<script src="Array.js"></script>
- <script src="String.js"></script>
<script>
mocha.run();
</script>