I'm trying to run some unit tests using QUnit written in CoffeeScript but there seems to be some reserved words that are causing problems, most notably "not". Is there a way to escape a CoffeeScript reserved word? Here's a simple test that demonstrates the problem:
module "Sad face test"
test "will not co开发者_JAVA技巧mpile", ->
not false, "holy crap this creates a syntax error :-("
The error this generates is "Parse error on line 3: Unexpected ','"
The best answer I have been able to find is to escape into JavaScript and alias the function:
notEqual = `not`
module "Sad face test"
test "will not compile", ->
notEqual false, "holy crap this creates a syntax error :-("
Although it looks like not
isn't a function within the latest version of QUnit, so in this specific instance you may not need to to escape a CoffeeScript reserved word.
The not
function is global, so it's actually attached to window
, right? Instead of backtick escapes, then, you can just write
window.not
instead of not
; or
notEqual = window.not
精彩评论