在Ruby中,我可以使用
target_files = Dir["/some/dir/path/*.rb"]
#=> ["/some/dir/path/foo.rb", "/some/dir/path/bar.rb", "/some/dir/path/baz.rb"]
Run Code Online (Sandbox Code Playgroud)
它将返回目录中所有匹配文件的数组.我怎样才能在Elixir中做类似的事情?
JS新手在这里。
我已经生成了一个 Nuxt 应用程序并@nuxt/auth在我的nuxt.config.js. 它在我的应用程序中按预期工作。
现在我想测试一些引用该$auth对象的组件。
// ~/components/hello_component.vue
<template>
<div>
<div v-if="$auth.loggedIn">
<h1>Hi, {{ userName }}</h1>
</div>
</div>
</template>
<script>
export default {
data () {
userName: "Archduke Chocula"
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
我有一个看起来像这样的测试:
// ~/spec/components/hello_component.spec.js
import { mount } from '@vue/test-utils'
import Hello from '@/components/hello_component.vue'
describe('Hello Component', () => {
test('is a Vue instance', () => {
const wrapper = mount(Hello)
expect(wrapper.isVueInstance()).toBeTruthy()
})
})
Run Code Online (Sandbox Code Playgroud)
这导致以下错误
Error in render: "TypeError: Cannot read property 'loggedIn' of …Run Code Online (Sandbox Code Playgroud) 如何测试以下代码?
["one", "two", "three"]) |> Enum.each(&IO.puts(&1))
one
two
three
:ok
Run Code Online (Sandbox Code Playgroud)
我的测试目前看起来像这样,但失败了,因为IO.puts返回:ok而不是字符串,并且可能不包括完整字符串中的换行符。
assert ["one", "two", "three"]) |> Enum.each(&IO.puts(&1)) == """
one
two
three
"""
Run Code Online (Sandbox Code Playgroud)
也许IO.puts是这个用例的错误功能。如果是这样,我可以使用什么替代方案?
提前致谢。
在 Elixir 中更新嵌套 Map 中的值时,我们可以使用 Kernel.put_in/3
map = %{hi: "what's", up: %{my: "boii"}}
%{hi: "what's", up: %{my: "boii"}}
Kernel.put_in(map, [:up, :my], "dawg")
%{hi: "what's", up: %{my: "dawg"}}
Run Code Online (Sandbox Code Playgroud)
Map.put/3考虑到它们的输入和结果非常相似,为什么不定义此函数?
elixir ×3
collections ×1
directory ×1
ex-unit ×1
file ×1
jestjs ×1
nuxt.js ×1
stdout ×1
unit-testing ×1
vue.js ×1