编辑:解决了!向下滚动以查找答案
在我们的组件测试中,我们需要他们可以访问react-intl上下文.问题是我们在mount()没有<IntlProvider />父包装的情况下安装单个组件(使用Enzyme ).这可以通过将提供程序包装起来然后将root点指向IntlProvider实例来解决,而不是CustomComponent.
该测试与阵营-国际:酶文档仍然是空的.
<CustomComponent />
class CustomComponent extends Component {
state = {
foo: 'bar'
}
render() {
return (
<div>
<FormattedMessage id="world.hello" defaultMessage="Hello World!" />
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
标准测试案例(所需)(酶+摩卡+柴)
// This is how we mount components normally with Enzyme
const wrapper = mount(
<CustomComponent
params={params}
/>
);
expect( wrapper.state('foo') ).to.equal('bar');
Run Code Online (Sandbox Code Playgroud)
但是,由于我们的组件FormattedMessage用作react-intl库的一部分,因此在运行上述代码时会出现此错误:
Uncaught Invariant Violation: [React Intl] …
我已经多次生成了一个bundle(@ShopfishApiBundle)generate:bundle.它会自动注册到捆绑AppKernel,并将其列入了包的的装载routing.yml到app/Resource/config/routing.yml为好.这是在Sylius安装运行中Symfony 2.3
该@ShopfishApiBundle/Resource/config/routing.yml如下所示:
shopfish_api:
resource: "@ShopfishApiBundle/Controller/ProductController.php"
type: annotation
Run Code Online (Sandbox Code Playgroud)
产品控制器如下所示:
namespace Shopfish\Bundle\ApiBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
/**
* @Route("/api")
*/
class ProductController extends Controller
{
/**
* @Route("/products")
* @Method({"GET"})
*
* @Rest\View
*/
public function allAction()
{
$products = array();
return array('products' => $products);
}
}
Run Code Online (Sandbox Code Playgroud)
立即加载任何页面会产生以下异常:
FileLoaderLoadException: Cannot load resource "@ShopfishApiBundle/Controller/". Make sure the "ShopfishApiBundle" bundle is correctly registered and loaded in …Run Code Online (Sandbox Code Playgroud)