JavaScript How to mark a jasmine test as failed?

I have a jasmine 2.0 test that if a function is called, the test failed.

I have a function "Remote.get" that should call the first argument (which is a callback) if it is successful, or the second argument if it failed.

If it calls the second argument, I need to mark the test as failed.

How can I clearly mark the test as failed?

describe("my tests", function() {
  it("should call the first function", function(done) {          
    Remote.get(
      function() {
        // yeah! good!
        done();
      },
      function() {

        // whoa, if we got here, then it didn't work
        // fail()!

        done();
      }
    );             
  });
});

I know I could do something like expect(true).toBe(false) but I the error you get then would be unclear and unrelated to the actual problem. It should give an error like "wrong callback was called" or "Remote.get failure was called". I was hoping there was something more descriptive in Jasmine.

What I'm really looking for is the python equivalent of http://docs.python.org/2/library/unittest.html#unittest.TestCase.fail.

Answer:1

You could write and register a custom matcher whose compare function in the return value always fails, and assign your custom message to the message property

Answer:2

I'm new to promises and writing network code using requests and promises in NodeJS. I would like to remove these nested promises and chain them instead, but I'm not sure how I'd go about it/whether ...

I'm new to promises and writing network code using requests and promises in NodeJS. I would like to remove these nested promises and chain them instead, but I'm not sure how I'd go about it/whether ...

  1. remove nested promises

I'm using IntelliJ IDEA 12 Community Edition, and am trying to set the syntax coloring for Javascript files. When I choose File > Settings > IDE Settings > Editor > Colors & Fonts, Javascript is ...

I'm using IntelliJ IDEA 12 Community Edition, and am trying to set the syntax coloring for Javascript files. When I choose File > Settings > IDE Settings > Editor > Colors & Fonts, Javascript is ...

  1. intellij community javascript syntax highlighting

The last few days, I've been helping a friend learn Javascript. It's his first language in years and he remembers virtually nothing, so he's been starting pretty much entirely from scratch. He's been ...

The last few days, I've been helping a friend learn Javascript. It's his first language in years and he remembers virtually nothing, so he's been starting pretty much entirely from scratch. He's been ...

I know about Workspaces recently introduced in DevTools but that is not that i need. For example: page uses jquery that is loaded from CDN, i modify jquery library code, press ctrl-s, reload page -> ...

I know about Workspaces recently introduced in DevTools but that is not that i need. For example: page uses jquery that is loaded from CDN, i modify jquery library code, press ctrl-s, reload page -> ...