Created
November 28, 2017 00:03
-
-
Save killmenot/dbf8ec5f8f1a51cf08f612a3af9227fb to your computer and use it in GitHub Desktop.
Testing from a file, Jasmine
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
var fs = require('fs'); | |
function Account(file) { | |
this._file = file; | |
} | |
Account.prototype.readfile = function () { | |
if (!this._file) { | |
throw new Error('File not found') | |
} | |
this._data = fs.readFileSync(this._file, 'utf8') | |
return true | |
} | |
Account.prototype.toDowncase = function () { | |
return this._data.toLowerCase() | |
} | |
Account.prototype.removeWords = function () { | |
return this._data.replace(/\W/g, " ") | |
} | |
module.exports = Account; |
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
var Account = require('../../lib/test'); | |
var fs = require('fs') | |
describe('wordCount', function () { | |
var account; | |
var file = '/path/to/file'; | |
beforeEach(function () { | |
account = new Account(file); | |
}); | |
describe("When changing the format of the text file", function () { | |
it('will change all the words to lowercase', function () { | |
spyOn(fs, 'readFileSync').and.returnValue('Hello World'); | |
account.readfile(); | |
var actual = account.toDowncase(file) | |
expect(actual).toEqual('hello world'); | |
}); | |
it('will remove non-words', function () { | |
spyOn(fs, 'readFileSync').and.returnValue('Hello#World'); | |
account.readfile(); | |
var actual = account.removeWords() | |
expect(actual).toEqual('Hello World'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment