首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用@inrupt/solid-client模拟Container?

如何使用@inrupt/solid-client模拟Container?
EN

Stack Overflow用户
提问于 2020-12-29 19:08:44
回答 1查看 28关注 0票数 1

如果我使用试图从容器读取的npm包@inrupt/solid-client为代码编写单元测试,我如何模拟该容器?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-29 19:08:44

从技术上讲,容器是一个常规的资源,它包含的每个资源都有一个Thing,并且有一样东西是由容器自己的指向它们的URL标识的。

因此,下面的代码应该可以做到这一点:

代码语言:javascript
运行
复制
// We're going to mock a Container at https://vincentt.inrupt.net/public/,
// that contains one Resource at https://vincentt.inrupt.net/public/child-one.ttl.

const containerUrl = "https://vincentt.inrupt.net/public/";

// Add a Thing for the child at
// https://vincentt.inrupt.net/public/child-one.ttl:
let childOneListing = createThing({ url: containerUrl + "child-one.ttl" });
childOneListing = addUrl(childOneListing, rdf.type, ldp.Resource);
childOneListing = addDatetime(childOneListing, dct.modified, new Date());

// Create a Thing identified by the Container's own URL,
// pointing to the Things representing its children:
let childrenIndex = createThing({ url: containerUrl });
childrenIndex = addUrl(childrenIndex, rdf.type, ldp.BasicContainer);
childrenIndex = addUrl(childrenIndex, rdf.type, ldp.Container);
// Add child-one.ttl to this index:
childrenIndex = addUrl(childrenIndex, ldp.contains, childOneListing);

// Now initialise a mock Resource for this Container for use in our unit test,
// and add the index and the child Resources' Things:
let mockContainer = mockSolidDatasetFrom(containerUrl);
mockContainer = setThing(mockContainer, childrenIndex);
mockContainer = setThing(mockContainer, childOneListing);

可以在以下位置找到包含上述代码的CodeSandbox:https://codesandbox.io/s/ancient-wood-3u8m3?fontsize=14&hidenavigation=1&theme=dark

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65491171

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档