nathanboktae / mocha-casperjs

Write CasperJS tests using Mocha
MIT License
120 stars 29 forks source link

Can't access the test property #13

Closed gish closed 10 years ago

gish commented 10 years ago

Description

Accessing the this.test property in a test results in error

$ npm-exec mocha-casperjs gui.coffee --casper-chai-path=node_modules/casper-chai/lib/casper-chai --expect

  localhost
    1) can be opened
CasperError: casper.test property is only available using the `casperjs test` command
  [...]/node_modules/casperjs/modules/casper.js:179

Reproduce

Run the following test

describe "localhost", ->
  casper.start "http://localhost/", ->
    @viewport 1000, 1000

  it "can be opened", ->
    casper.then ->
      @echo this.test.title
      expect(casper.currentHTTPStatus).to.equal 200

Expected behavior

Casper shouldn't throw any errors.

nathanboktae commented 10 years ago

Casper always binds this to itself, so what you want is:

describe "localhost", ->
  casper.start "http://localhost/", ->
    @viewport 1000, 1000

  it "can be opened", ->
    test = @test
    casper.then ->
      @echo test.title  # or test.fullTitle()
      expect(casper.currentHTTPStatus).to.equal 200
gish commented 10 years ago

Thanks!