Buster.JSに用意されているassertion一覧


```
xUnit style
BDD style
//概要
```
の順番で列挙

```javascript
assert(actual[, message])
expect(actual).toBeTruthy()
expect(actual).not.toBeFalsy()//これも使える
//actualが(0, "", null, undefined, NaN)でなければpass

assert.same(actual, expected[, message])
expect(actual).toBe(expected)
//actual === expectedであればpass

assert.equals(actual, expected[, message])
expect(actual).toEqual(expected)
//actual == expectedであればpass
//objectの場合はpropertyの値が同じであればpass

assert.greater(actual, expected[, message])
expect(actual).toBeGreaterThan(expected)
//actual > expectedであればpass

assert.less(actual, expected[, message])
expect(actual).toBeLessThan(expected)
//actual < expectedであればpass

assert.defined(actual[, message])
expect(actual).toBeDefined()
//typeof actual != "undefined"であればpass

assert.isNull(object[, message])
expect(actual).toBeNull()
//actual === nullであればpass

assert.match(actual, matcher[, message])
expect(actual).toMatch(matcher)
//matcherが何であるかによって挙動がかなりかわるのでソース貼付け
//if (matcher && typeof matcher.test == "function") {
//  return matcher.test(actual);//}//if (typeof matcher == "function") {//  return matcher(actual) === true;//}
//if (typeof matcher == "string") {//  matcher = matcher.toLowerCase();//  var notNull = typeof object === "string" || !!object;//  return notNull && ("" + object).toLowerCase().indexOf(matcher) >= 0;//}//if (typeof matcher == "number") {//  return matcher == object;//}//if (typeof matcher == "boolean") {//  return matcher === object;//}//if (matcher && typeof matcher == "object") {//  for (var prop in matcher) {//    if (!match(object[prop], matcher[prop])) {//      return false;//    }//  }
//  return true;//}

assert.isObject(actual[, message])
expect(actual).toBeObject()
//typeof actual == "object" && !!actualであればpass

assert.isFunction(actual[, message])
expect(actual).toBeFunction()
//typeof actual == "function"であればpass

assert.isTrue(actual[, message])
expect(actual).toBeTrue()
//actual === trueであればpass

assert.isFalse(actual[, message])
expect(actual).toBeFalse()
//actual === falseであればpass

assert.isString(actual[, message])
expect(actual).toBeString()
//typeof actual == "string"であればpass

assert.isBoolean(actual[, message])
expect(actual).toBeBoolean()
//typeof actual == "boolean"であればpass

assert.isNumber(actual[, message])
expect(actual).toBeNumber()
//typeof actual == "number" && !isNaN(actual)であればpass

assert.isNaN(actual[, message])
expect(actual).toBeNaN()
//typeof actual == "number" && isNaN(actual)であればpass

assert.isArray(actual[, message])
expect(actual).toBeArray()
//toString.call(actual) == "[object Array]"であればpass

assert.isArrayLike(actual[, message])
expect(actual).toBeArrayLike()
//Arrayか、lengthやspliceなどを調べてArrayらしければpass

assert.exception(callback[, exception, message])
expect(callback).toThrow([exception, message])
//errorをthrowすればpass

assert.near(actual, expected, delta[, message])
expect(actual).toBeNear(expected, delta)
expect(actual).toBeCloseTo(expected, delta)
//Math.abs(actual - expected) <= deltaであればpass

assert.hasPrototype(actual, protoObj[, message])
expect(actual).toHavePrototype(protoObj)
//protoObjがactualのprototypeであればpass

assert.contains(haystack, needle[, message])
expect(haystack).toContain(needle)
//haystack(Array)にneedleが含まれればpass

assert.tagName(element, tagName[, message])
expect(element).toHaveTagName(tagName)
//element.tagName.toLowerCase() == tagName.toLowerCase()であればpass

assert.className(element, className[, message])
expect(element).toHaveClassName(className)
//elementのclassにclassNameが含まれればpass

```

##Sinon.JSの spy と stub を使ったテストで使える

```javascript
assert.called(spy[, message])
expect(spy).toHaveBeenCalled()
//spyが1度でも呼ばれていればpass

assert.callOrder(spy, spy2[, ...])
//BDD style なぜかなさそう。
//spy, spy2[, ...]の順番で呼ばれていればpass

assert.calledOnce(spy[, message])
expect(spy).toHaveBeenCalledOnce(expected)
//spyが1度だけ呼ばれていればpass

assert.calledTwice(spy[, message])
expect(spy).toHaveBeenCalledTwice(expected)
//spyが2度だけ呼ばれていればpass

assert.calledThrice(spy[, message])
expect(spy).toHaveBeenCalledThrice(expected)
//spyが3度だけ呼ばれていればpass

assert.calledOn(spy, thisObj[, message])
expect(spy).toHaveBeenCalledOn(thisObj)
//spyが1度でもthisObjから呼ばれていればpass

assert.alwaysCalledOn(spy, thisObj[, message])
expect(spy).toHaveAlwaysBeenCalledOn(thisObj)
//spyが常にthisObjから呼ばれていればpass

assert.calledWith(spy, arg[, arg2, ...])
expect(spy).toHaveBeenCalledWith(arg1[, arg2, ...])
//spyが引数arg[, arg2, ...]と一緒に1度でも呼ばれていればpass

assert.alwaysCalledWith(spy, arg[, arg2, ...])
expect(spy).toHaveAlwaysBeenCalledWith(arg[, arg2, ...])
//spyが引数arg[, arg2, ...]と一緒に常に呼ばれていればpass

assert.calledOnceWith(spy, arg[, arg2, ...])
expect(spy).toHaveBeenCalledOnceWith(arg[, arg2, ...])
//spyが引数arg[, arg2, ...]と一緒に一度だけ呼ばれていればpass

assert.calledWithExactly(spy, arg[, arg2, ...])
expect(spy).toHaveBeenCalledWithExactly(arg[, arg2, ...])
//

assert.alwaysCalledWithExactly(spy, arg[, arg2, ...])
expect(spy).toHaveAlwaysBeenCalledWithExactly(arg[, arg2, ...])
//

assert.threw(spy, arg)
expect(spy).toHaveThrown(arg)
//

assert.alwaysThrew(spy, arg)
expect(spy).toAlwaysHaveThrown(arg)
//


```

##否定
assertの代わりにrefuteを使う
expectはnotを挟む(refuteだけは対応するメソッドがある)

```javascript
refute.same(actual, expected[, message])
expect(actual).not.toBe(expected)

refute(actual[, message])
expect(actual).toBeFalsy()
expect(actual).not.toBeTruthy()//これも使える

```

英語が出来る人は、BDDって直感的なんだろうなぁ。
出来ない人にとってはxUnitのと比べてがタイプが多いと感じるな。