I wrote a test a while back and had some trouble with it but was able to get it working with help from the community:
It’s been working ever since, but now, after an upgrade, it’s failing. The cause is that mockGraphQLQuery is not being called for some reason. The code I’m testing is:
import { useQuery } from '@redwoodjs/web';
const GET_TENANT = gql`
query getTenant($domain: String!) {
tenantByDomain(domain: $domain) {
id
domain
}
}
`;
const useTenant = () => {
// this should be an admin domain so it should end with `-admin`.
// e.g. foo-admin.example.com
// 1. strip the subdomain off, should be left with `foo-admin`
const adminSubdomain = window.location.host.split('.')[0];
// 2. strip the `-admin` off
const subdomain = adminSubdomain.substring(
0,
adminSubdomain.indexOf('-admin')
);
return useQuery(GET_TENANT, {
variables: { domain: subdomain },
});
};
export default useTenant;
This is on v7.4.2. I have a copy of the code on v5.0.2 and it works fine there. Were there any changes to mockGraphQLQuery that might be causing this? Any idea why it might be failing to be called now?
While there have been version upgrades and such (quite a big leap from v5 to v7!) - I don’t see the usual suspects that may be causing this.
My suggestion here:
Double check the upgrade guides to make sure you followed all the steps. This is a silly suggestion, but quite often where things go wrong!
If this doesn’t work, could you help us with a minimal reproduction? The process of doing this might actually reveal the issue, and if not give us something for us to work with
If this doesn’t work, could you help us with a minimal reproduction? The process of doing this might actually reveal the issue, and if not give us something for us to work with
As I began putting together a minimal test-case I found the problem. While trying to track down the problem I think at one point I thought maybe this line was the problem:
This code is right before mockGraphQLQuery so it gave me the illusion that it wasn’t working, but it wasn’t a problem with mockGraphQLQuery, the test quit before it got that far. My test is working again. Thank you for your help. Here is my working test: