注意:以下翻译的准确性尚未经过验证。这是使用 AIP ↗ 从原始英文文本进行的机器翻译。
您可以使用 Objects.create()
创建和定义您的模拟对象,这与使用常规函数的方式相同。然后,您可以在编写单元测试时使用这些模拟对象。以下是一个示例:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import { MyFunctions } from ".." import { Objects, ExampleDataAirport } from "@foundry/ontology-api"; describe("example test suite", () => { const myFunctions = new MyFunctions(); test("test created objects", () => { // 创建一个名为 JFK 的机场对象 const JFK = Objects.create().exampleDataAirport("JFK Test"); // 设置机场的显示名称为 "John F. Kennedy International" JFK.displayAirportName = "John F. Kennedy International"; // 断言 myFunctions.getAirportName(JFK) 返回的值应为 "John F. Kennedy International" expect(myFunctions.getAirportName(JFK)).toEqual("John F. Kennedy International"); }); });
供参考,上述示例使用的是Jest语法expect(...).toEqual(...)
↗。