我正在使用酶来测试反应组分。我使用的以前版本的酶允许我使用节点或节点访问子节点及其成员变量。现在我使用的新版本的酶使我使用getElement
函数来访问子组件。并且getElement
不允许我直接访问节点或节点(不支持)。如何使用-- Imput: @justWeekEnding - the date for the end of week report
-- Input: @customerid - the unique customer ID for whom the report is generated
-- Expected output: Sales report, showing profit margin for the selected customer per shop per day-of-week
--
-- dbo.charting_salesdata: View producing a sales report across all stores per date per customer
-- dbo.stores: Table containing store info
-- dbo.receipts: Table containing all receipts
-- dbo.storecategories: Table containing all store categories
DECLARE @justWeekEnding AS date;
SET @justWeekEnding = CONVERT(date, @weekEnding, 101);
SELECT
Query.StoreName AS [Store Name], Query.POS as [POS Name],
Query.saturday, Query.sunday, Query.monday, Query.tuesday,
Query.wednesday, Query.thursday, Query.friday
FROM
(SELECT
dbo.stores.NAME AS [StoreName],
receipts.POS AS [POS],
(SELECT COUNT(percentage)
FROM dbo.charting_salesdata WITH (nolock)
WHERE dbo.charting_salesdata.receiptid = dbo.receipts.receiptid
AND dateofsale = Dateadd(d, -6, @justWeekEnding)
GROUP BY receiptid, dateofsale) AS saturday,
(SELECT COUNT(percentage)
FROM dbo.charting_salesdata WITH (nolock)
WHERE dbo.charting_salesdata.receiptid = dbo.receipts.receiptid
AND dateofsale = Dateadd(d, -5, @justWeekEnding)
GROUP BY receiptid, dateofsale) AS sunday,
(SELECT COUNT(percentage)
FROM dbo.charting_salesdata WITH (nolock)
WHERE dbo.charting_salesdata.receiptid = dbo.receipts.receiptid
AND dateofsale = Dateadd(d, -4, @justWeekEnding)
GROUP BY receiptid, dateofsale) AS monday,
(SELECT COUNT(percentage)
FROM dbo.charting_salesdata WITH (nolock)
WHERE dbo.charting_salesdata.receiptid = dbo.receipts.receiptid
AND dateofsale = Dateadd(d, -3, @justWeekEnding)
GROUP BY receiptid, dateofsale) AS tuesday,
(SELECT COUNT(percentage)
FROM dbo.charting_salesdata WITH (nolock)
WHERE dbo.charting_salesdata.receiptid = dbo.receipts.receiptid
AND dateofsale = Dateadd(d, -2, @justWeekEnding)
GROUP BY receiptid, dateofsale) AS wednesday,
(SELECT COUNT(percentage)
FROM dbo.charting_salesdata WITH (nolock)
WHERE dbo.charting_salesdata.receiptid = dbo.receipts.receiptid
AND dateofsale = Dateadd(d, -1, @justWeekEnding)
GROUP BY receiptid, dateofsale) AS thursday,
(SELECT COUNT(percentage)
FROM dbo.charting_salesdata WITH (nolock)
WHERE dbo.charting_salesdata.receiptid = dbo.receipts.receiptid
AND dateofsale = @justWeekEnding
GROUP BY receiptid, dateofsale) AS friday,
(SELECT COUNT(percentage)
FROM dbo.charting_salesdata WITH (nolock)
WHERE dbo.charting_salesdata.receiptid = dbo.receipts.receiptid
AND dateofsale BETWEEN Dateadd(d, -6, @justWeekEnding) AND @justWeekEnding) AS TOTAL
FROM
receipts WITH (nolock)
INNER JOIN
dbo.stores WITH (nolock) ON dbo.receipts.storeid = dbo.stores.storeid
INNER JOIN
dbo.storecategories WITH (nolock) ON dbo.stores.storecategoryid = dbo.storecategories.storecategoryid
WHERE
1=1
AND customerid = @customerid
AND dbo.receipts.isdeleted = 0) AS Query
WHERE
Query.TOTAL > 0
ORDER BY
Query.StoreName, Query.TargetName
设置子组件的成员变量?
答案 0 :(得分:0)
您不会被迫使用getElement
。以下是我们如何进行单元测试的示例:
it('should pass entered password to password child textfield', () => {
const inputPassword = 'gold please';
const wrapper = enzyme.shallow((
<Login
emailAddress=""
password={inputPassword}
loggingIn={false}
isValid={true}
loginAutofilled={false}
classes={{}}
onEmailChanged={email => null}
onPasswordChanged={password => null}
onLoginAsGuest={() => null}
onLogin={(email, password) => null}
onResetPassword={() => null}
onLoginAutofilled={() => null}
/>
));
// There is an input element with an ID of 'login-form_password-field'
const passwordField = wrapper.find('#login-form_password-field');
expect(passwordField.props().value).toEqual(inputPassword);
});
});