"And God tested Abraham" (Genesis 22:1). This is what Scripture says: "You have given those who fear You a banner to be displayed (nes lehitnoses)" (Psalms 60:6) — a refuge (manos) through which Israel was rescued from the judgment of Gehinnom. (Another interpretation: "a banner to be displayed") "because of truth, Selah" — in order to give their reward in truth, as it is said, "And I will give their recompense in truth" (Isaiah 61:8). But the wicked have no refuge, as it is said, "But the eyes of the wicked shall fail, and refuge shall be lost to them" (Job 11:20). "You have given those who fear You a banner." Come and see the difference between the first ones and the last ones, for the first ones were tested by the Holy One, blessed be He, as it is said, "And God tested Abraham," and likewise the people of the wilderness generation, as it is said, "that I may test them, whether they will walk in My Torah or not" (Exodus 16:4), and likewise it says, "in order to afflict you [and in order] to test you" (Deuteronomy 8:16). But the last ones were tested by the nations, as it is said, "Now these are the nations that the LORD left, to test Israel by them" (Judges 3:1). Thus, "You have given those who fear You a banner to be displayed because of truth, Selah." What is "because of truth, Selah"? Whoever was tested and stood firm in the trials. And so you find with Daniel and his companions: when they were exiled, the Holy One, blessed be He, decreed upon them that they would eat unclean bread, as it is said, "Thus shall the children of Israel eat their bread unclean among the nations where I will drive them" (Ezekiel 4:13). Nebuchadnezzar arose and carried out the matter; he began and said: I decree that they shall eat of my food, as it is said, "And the king appointed for them" (Daniel 1:5). Daniel did not accept it upon himself, but said: Even though the Holy One, blessed be He, decreed upon us that we should eat unclean bread, He sought to test us — rather, let us do our part, and the Holy One, blessed be He, will do His part. He began to say to the chief of the guards: "I beseech you, please test your servants ten days, [and let them give us legumes to eat and water to drink, and let our appearance be examined before you, and the appearance of the youths who eat the king's food, and as you see, deal with your servants]" (Daniel 1:12-13). He said to them: Are you able to be tested ten days, not to eat bread and not to drink wine? They said to him: Yes, for we are of the children's children of that man who was tested with ten trials by God; may his merit stand for us, as it is said, "please test your servants" (Daniel 1:12). Have you not already found us ten times better (than the magicians)? By whose merit? By the merit of Abraham, who was tested with ten trials. Since they stood firm in their trial, what is written? "And God gave Daniel [favor and compassion before the chief of the eunuchs (Daniel 1:9), and he heeded them in this matter and tested them ten days, and at the end of ten days their appearance was seen to be better and fatter of flesh than all the youths who ate the king's food (Daniel 1:14-15)]." Thus, "You have given those who fear You a banner to be displayed." What is "a banner"? You make them great, as it is said, "and like a banner on a hill" (Isaiah 30:17). And why did the Holy One, blessed be He, test them? In order to make them great, so as not to give an opening for the nations of the world to say: He makes them great, yet He did not test them and they did not stand firm in their trial. Therefore, "after these things, [and God tested Abraham]" (Genesis 22:1).
Why God Tested Abraham and Daniel Refused the King's Bread
Midrash Tanchuma Buber, Vayera 43:1
והאלהים נסה את אברהם. זש"ה נתת ליראיך נס להתנוסס (תהלים ס ו), מנוס שנוצלו ישראל מדינה של גיהנם, (ד"א נס להתנוסס) מפני קושט סלה. כדי ליתן שכרו בקושט, שנאמר ונתתי פעולתם באמת (ישעיה סא ח), אבל הרשעים אין להם מנוס, שנאמר ועיני רשעים תכלינה ומנוס אבד מנהם (איוב יא כ). נתת ליראיך נס. בא וראה מה בין הראשונים לאחרונים, שהראשונים היו מתנסים ע"י הקב"ה, שנאמר והאלהים נסה את אברהם, וכן באנשי דור המדבר, שנאמר למען אנסנו הילך בתורתי אם לא (שמות טז ד), וכן הוא אומר למען ענותך [ולמען] נסותך וגו' (דברים ח טז), אבל האחרונים נתנסו על ידי האומות, שנאמר ואלה הגוים אשר הניח ה' לנסות בם את ישראל (שופטים ג א), הרי נתת ליראיך נס להתנוסס מפני קושט סלה, מאי מפני קושט בסלה, מי נתנסה ועמד בנסיונות, וכן אתה מוצא בדניאל וחביריו כשגלו גזר עליהם הקב"ה שיאכלו לחם טמא, שנאמר ככה יאכלו בני ישראל את לחמם טמא בגוים אשר אדיחם שם (יחזקאל ד יג), עמד נבוכדנצר וקיים את הדבר, התחיל ואמר גוזר אני שיהו אוכלים מאכילה שלי, שנאמר וימן להם המלך וגו' (דניאל א ה), דניאל לא קיבל עליו אלא אמר אע"פ שגזר הקב"ה עלינו שנאכל לחם טמא, בקש לנסות אותנו, אלא נעשה שלנו, והקב"ה יעשה שלו, התחיל לומר לשר הטבחים בבקשה ממך נס נא את עבדיך ימים עשרה [ויתנו לנו מן הזרועים ונאכלה ומים ונשתה ויראה לפניך מראינו ומראה הילדים האוכלים את פת בג המלך וכאשר תראה עשה עם עבדיך] (דניאל א י ביג), אמר להם ואתם יכולים להתנסות ימים עשרה שלא לאכול לחם ושלא לשתות יין, אמרו לו הן, שאנו מבני בניו של אותו האיש שנתנסה בעשר נסיונות מן האלהים, זכותו תעמוד לנו, שנאמר נס נא את עבדיך (דניאל א יב), לא כבר מצאת אותנו עשר ידות (על החרטומים, בזכות מי, בזכות אברהם, שנתנסה בעשר נסיונות, כיון שעמדו בנסיונם מה כתיב, ויתן האלהים את דניאל [לחסד ולרחמים לפני שר הסריסים (שם שם ט), וישמע להם לדבר הזה וינסם ימים עשרה ומקצת ימים עשרה נראה מראיהם טוב ובריאי בשר מן כל הילדים האוכלים את פת בג המלך (שם ש יד טו) ]. הוי נתת [ליראיך נס להתנוסס], מהו נס, גודלת אותם, כמה שנאמר וכנס על הגבעה (ישעיה ל יז), ולמה נסה אותם הקב"ה בשביל לגדלם, כדי שלא ליתן פתחון פה לאומות העולם לומר הוא מגדלן והוא לא נסה אותן ועמדו בנסיונן, לפיכך אחר הדברים האלה [והאלהים נסה את אברהם].