andyhmltn / ember-js-chatapp

MIT License
3 stars 1 forks source link

Add tests #5

Open andyhmltn opened 11 years ago

andyhmltn commented 11 years ago

This really needs unit tests.

zspecza commented 11 years ago

I have access to a video that outlines ember.js debugging in the developer console very well (as well as some other tips), as for testing - mocha + chai is the best.

andyhmltn commented 11 years ago

Awesome. Yeah I'm gunna look at different testing options. JavaScript doesn't seem to have the same solid options as something like python or ruby

zspecza commented 11 years ago

you'd be surprised - it really does. Mocha is just a base with no assertions library - use something like Chai and you have both BDD and TDD. Jasmine's also pretty good for the browser side.

andyhmltn commented 11 years ago

I played about with Jasmine yesterday. Seems a lot like rspec which is awesome.

zspecza commented 11 years ago

Mocha + chai have the exact same syntax - but with Mocha you can write tests in coffeescript. i.e.

chai = require 'chai'
do chai.should

{User} = require '../user'

describe 'User', ->

    user = null

    it 'should have a name', ->
        user = new User 'Declan'
        user.name.should.equal 'Declan'

    it 'should initially be unactivated', ->
        user = new User 'Bob'
        user.active.should.equal false

    it 'should be able to be activated', ->
        user = new User 'Jim'
        user.activate().should.equal true
        user.active.should.equal true

    it 'should be able to set an email', ->
        user = new User 'Declan'
        user.setEmail('declandewet@me.com').should.equal 'declandewet@me.com'
        user.email.should.equal 'declandewet@me.com'

    it 'should be able to set a password', ->
        user = new User 'Steve'
        user.setPassword('pancakes').should.equal 'pancakes'
        user.password.should.equal 'pancakes'

Then with this Cakefile you can run $ cake test:

fs = require 'fs'
{exec} = require 'child_process'

task 'test', 'runs the tests', ->
    exec 'clear && mocha --compilers coffee:coffee-script --reporter spec --colors', (err, stdout, stderr) ->
        throw err if err
        console.log stdout + stderr
andyhmltn commented 11 years ago

Wow that's exactly what I needed! Thanks :)

andyhmltn commented 11 years ago

I'm having quite a few problems getting tests to work with this application. Is there any chance you can add a small test that sees if the message is sent where you pressenter or something and then do a pull request of you've got time? Only a little one just to give me an idea of how they will work in production

andyhmltn commented 11 years ago

I forgot to mention: could it be a browser based test? One that checks if an action is performed in the browser. That's the part I'm having trouble with