是否有可能使用chai断言数组包含多个特定项?
例如,我希望这可以工作:
['foo', 'bar'].should.include(['foo', 'bar'])
Run Code Online (Sandbox Code Playgroud)
相反,柴投掷:"预期['foo','bar']包括['foo','bar']"
我也试过这个,但它只断言第一个项目存在:
['foo', 'bar'].should.include('foo', 'bar') // variable args instead of array
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
当我尝试更新嵌入文档的属性(embeds_many)时,mongoid无法保存更改,并且奇怪地将更改的属性添加为父文档的新属性.这是一个简单的单元测试,说明了我要做的事情:
class Tab
include Mongoid::Document
field :name, :type => String
embeds_many :components, :class_name => 'TabComponent'
end
class TabComponent
include Mongoid::Document
embeds_many :components, :class_name => "TabComponent"
end
class TabColumn < TabComponent
field :width, :type => Integer
end
require 'test_helper'
class TabTest < ActiveSupport::TestCase
test "create new tab" do
tab = Tab.new({
:name => "My Demo Tab",
:components => [TabColumn.new({
:width => 200
})]
})
tab.save!
tab.components[0].width = 300
tab.save!
assert_equal tab.components[0].width, 300 # passes
tab.reload
assert_equal tab.components[0].width, 300 # fails!
end …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个webpack插件,该插件会累积与某种模式匹配的js require / import调用,在解决之前将它们从源中删除(因为解析将失败),然后将累积的信息传递给单独的捆绑包构建过程。如何使用插件修改源代码?此外,插件甚至是正确的方法吗?