我不明白为什么这个frisby测试不能运行!
基本上,我尝试从一个文件导入JSON,并根据请求返回的结果对其进行检查。当我运行这个文件时,编译器似乎找不到任何测试。
如果有人能提出一个更好的方法来做这件事呢?我正在考虑尝试一种不同的方式来处理文件读取。我知道readFileSync(),但如果没有必要,我不想使用它!任何帮助都将不胜感激。
function readContent(callback,url,file) {
fs.readFile(file, 'UTF8', function (err, content) {
if (err) return callback(err)
data = JSON.parse(content)
callback(null, data)
})
}
readContent(function (err, content) {
frisby.create('Testing API')
.get(url)
.expectStatus(200)
.expectBodyContains(content)
.toss()
},
url,file)发布于 2014-08-07 11:07:24
这是我之前准备的一个:
// Read a JSON file from disk, and compare its contents with what comes back from the API.
fs.readFile(path.resolve(__dirname, 'GET_ReferenceTypes.json'), 'utf-8', function(error, data){
if (error) throw error
frisby.create('GET ReferenceTypes, inside readFile callback')
.get(URL + 'ReferenceTypes?requestPersonId=2967&id=99')
.expectStatus(200)
// JSON.parse() is required to convert the string into a proper JSON object for comparison.
// The .replace() strips the BOM character from the beginning of the unicode file.
.expectJSON(JSON.parse(data.replace(/^\uFEFF/, '')))
.toss();
});仔细检查您的JSON文件的编码,因为整个过程没有调用.replace()就会被拆分。
https://stackoverflow.com/questions/20896153
复制相似问题