我正在尝试创建一个带有逻辑的afterEach挂钩,只有在前一次测试失败时才会触发.例如:
it("some_test1", function(){
// something that could fail
})
it("some_test2", function(){
// something that could fail
})
afterEach(function(){
if (some_test_failed) {
// do something to respond to the failing test
} else {
// do nothing and continue to next test
}
})
Run Code Online (Sandbox Code Playgroud)
但是,我没有办法在afterEach钩子中检测测试是否失败.是否有某种事件监听器我可以附加到摩卡?也许是这样的:
myTests.on("error", function(){ /* ... */ })
Run Code Online (Sandbox Code Playgroud) 在不使用/扩展Array类的情况下在Ruby中实现链表的最佳方法是什么?这是我过去使用的一个实现,但它似乎不是最好的方法:
class Node
attr_accessor :value, :next_node
def initialize(value = nil)
@value = value
end
def to_s
@value
end
end
class SinglyLinkedList
attr_accessor :head
def initialize(first_value=nil)
@head = Node.new(first_value) if first_value
end
def add(value)
#adds a new node to the list, amakes it the new head and links it to the former head
new_node = Node.new(value)
new_node.next_node = @head
@head = new_node
end
def remove
@head = @head.next_node
end
end
Run Code Online (Sandbox Code Playgroud)