Skip to content

Commit

Permalink
fix throwErr and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding committed Mar 13, 2020
1 parent 7c10479 commit b6c9631
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/driver/src/cypress/error_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const makeErrFromObj = (obj) => {

const throwErr = (err, options = {}) => {
if (_.isString(err)) {
err = cypressErr(err)
err = cypressErr({ message: err })
}

if (options.noStackTrace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ describe('src/cy/commands/assertions', () => {

it('throws err when not available chainable', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.eq('The chainer: \'dee\' was not found. Could not build assertion.')
expect(err.message).to.eq('The chainer `dee` was not found. Could not build assertion.')

done()
})
Expand All @@ -435,7 +435,7 @@ describe('src/cy/commands/assertions', () => {

it('throws err when ends with a non available chainable', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.eq('The chainer: \'eq2\' was not found. Could not build assertion.')
expect(err.message).to.eq('The chainer `eq2` was not found. Could not build assertion.')

done()
})
Expand Down Expand Up @@ -543,7 +543,7 @@ describe('src/cy/commands/assertions', () => {
const { lastLog } = this

expect(this.logs.length).to.eq(2)
expect(err.message).to.eq('The \'eventually\' assertion chainer has been deprecated. This is now the default behavior so you can safely remove this word and everything should work as before.')
expect(err.message).to.eq('The `eventually` assertion chainer has been deprecated. This is now the default behavior so you can safely remove this word and everything should work as before.')
expect(lastLog.get('name')).to.eq('should')
expect(lastLog.get('error')).to.eq(err)
expect(lastLog.get('state')).to.eq('failed')
Expand Down Expand Up @@ -752,7 +752,7 @@ describe('src/cy/commands/assertions', () => {
})
})

it('does not replaces instances of word: \'but\' with \'and\' for failing assertion', (done) => {
it('does not replaces instances of word \'but\' with \'and\' for failing assertion', (done) => {
cy.on('log:added', (attrs, log) => {
if (attrs.name === 'assert') {
cy.removeAllListeners('log:added')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,31 @@ $errorMessages = require("../../../../src/cypress/error_messages")

describe "driver/src/cypress/error_utils", ->
context ".throwErr", ->
it "throws the error as sent", ->
it "throws error as a cypress error when it is a message string", ->
fn = -> $errUtils.throwErr("Something unexpected")

expect(fn).to.throw().and.satisfy (err) ->
expect(err.message).to.include "Something unexpected"
expect(err.name).to.eq "CypressError"

it "throws error when it is an object", ->
fn = -> $errUtils.throwErr({ name: "SomeError", message: "Something unexpected", extraProp: "extra prop" })

expect(fn).to.throw().and.satisfy (err) ->
expect(err.message).to.include("Something unexpected")
expect(err.name).to.eq("SomeError")
expect(err.extraProp).to.eq("extra prop")

it "throws error when it is an error", ->
err = new Error("Something unexpected")
err.extraProp = "extra prop"
fn = -> $errUtils.throwErr(err)

expect(fn).to.throw().and.satisfy (err) ->
expect(err.message).to.include("Something unexpected")
expect(err.name).to.eq("Error")
expect(err.extraProp).to.eq("extra prop")

it "removes stack if noStackTrace: true", ->
fn = -> $errUtils.throwErr("Something unexpected", { noStackTrace: true })

Expand Down

0 comments on commit b6c9631

Please sign in to comment.