我的简化jest.config.js是:
module.exports = {
preset: "ts-jest",
collectCoverage: true,
collectCoverageFrom: [
"src/**/*.ts",
"!**/node_modules/**",
"!src/config/*.ts",
"!build/**/*"
],
coverageReporters: ["text"],
reporters: ["default"],
moduleDirectories: [
"src",
"node_modules"
],
moduleNameMapper: {
"@helpers/(.*)": "<rootDir>/src/helpers/$1", <---- question about this
},
globals: {
'ts-jest': {
diagnostics: {
pathRegex: /\.(spec|test)\.ts$/,
ignoreCodes: [6133]
}
}
},
verbose: true,
roots: ["src"],
moduleFileExtensions: ["ts", "tsx", "js", "jsx"]
};
Run Code Online (Sandbox Code Playgroud)
moduleNameMapper 映射到任何级别的嵌套路径:
我在测试中使用它,例如import foo from "@helpers/foo/foo";
但是,我收到此错误:
无法找到
@helpers/foo映射为的模块:/<PATH>/src/helpers/foo
在文档中没有找到有关嵌套路径的任何内容。我认为,由于@helpers/(.*)是正则表达式,因此它应该可以开箱即用。
我究竟做错了什么?也许这是一个错误?
我是Ruby的初学者,遵循" 创建新的Rails项目 ".
但我无法启动服务器.我试过了:
跑步rails server但得到:
Could not find gem 'tzinfo-data <>= 0> x86-mingw32' in the gems available on the machine.
Run 'bundle install' to install missing gems.
Run Code Online (Sandbox Code Playgroud)跑步bundle install但得到:
An error occurred while installing rake (10.4.2), and Bundler cannot continue.
Make sure that 'gem install rake -v '10.4.2'' succeeds before bundling.
Run Code Online (Sandbox Code Playgroud)gem 'tzinfo-data' 但得到了:
Unknown command tzinfo-data
Run Code Online (Sandbox Code Playgroud)gem install tzinfo-data:
Could not find a valid gem 'tzinfo-data' <>= 0>, here is why:
Unable to …Run Code Online (Sandbox Code Playgroud)我对 API 主题真的很陌生。我已经从 API 显示了 JSON,阅读了大量文档,并且我了解如何将 JSON 键转换为 ruby 符号的想法,但我不明白如何实际执行它。我试过...
1)使用法拉第的方式。
2) 使用 JSON.parse
3) 使用 symbolize_keys: true
...和其他东西。
我的代码现在是什么样子的。我也评论了我尝试的方法,所以你可以看看。
class ProductsController < ApplicationController
require 'json'
def index
@products = Product.find(:all) # GET 'http://api.example.com/store/products.json'
products = Faraday.new(:url => 'http://api.example.com') do |faraday|
faraday.request :url_encoded
faraday.response :logger
faraday.adapter Faraday.default_adapter
end
#GET
response = products.get '/store/products.json'
response.body
products.get '/store', { :name => 'Koala' }
# @products = JSON.parse(@products, symbolize_keys: true)
end
end
Run Code Online (Sandbox Code Playgroud)
当前输出只是一个 JSON 字符串。我该如何解析这个?
Flowers99.0Guitar10.99Love20.0Penguin500.0Koala1000.0[...]
Run Code Online (Sandbox Code Playgroud)
超文本标记语言
= @products.each do |product|
tr …Run Code Online (Sandbox Code Playgroud) 我是javascript新手,但仍然倾向于尝试自己解决问题。但是,我很沮丧,因为没有tbody和thead的同一个函数适用于稍有不同的HTML 。
我得到的错误是->未捕获的TypeError:无法读取null的属性'insertRow'。
我哪里错了?也可能有更好的方法添加表行?我尝试了.append,但对我不起作用。
的HTML
<table class="table table-striped myTable">
<button class="btn btn-primary btn-lg" id="addTableRow">Add table row</button>
<thead>
<tr>
<th>Name</th>
<th>Surname</th>
<th>Email</th>
<th>City</th>
<th>Sex</th>
<th>Date</th>
<th>Time</th>
</tr>
</thead>
<tbody>
<tr id="firstRow">
<td>John</td>
<td>Morgan</td>
<td>mail@mail.com</td>
<td>London</td>
<td>Male</td>
<td>09.12.14</td>
<td>04:17 a.m.</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
的JavaScript
$("#addTableRow").click( function(){
var table = document.getElementById("myTable");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
var cell6 …Run Code Online (Sandbox Code Playgroud) 我遇到了一个函数,它的setTimeout内部超时呈指数级增长(timeout *= 2).
let timeout = 10000
function foo() {
// doSomething without breaking, returning
setTimeout(foo, timeout)
timeout *= 2;
}
foo()
Run Code Online (Sandbox Code Playgroud)
看起来这不应该是一个问题,并且直觉上感觉setInterval有点已经做了同样的事情(有一个无限循环,直到它被取消,如果有的话),然而,我的问题在于方法本身.